Search in sources :

Example 11 with ToVertices

use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.

the class ToVerticesHandlerTest method shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex.

@Test
public void shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex() throws OperationException {
    // Given
    final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null));
    final ToVerticesHandler handler = new ToVerticesHandler();
    final ToVertices operation = mock(ToVertices.class);
    given(operation.getInput()).willReturn(elementIds);
    given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.EQUAL);
    // When
    final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertThat(Sets.newHashSet(results)).containsOnly(vertex1, vertex3, vertex5, vertex7);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 12 with ToVertices

use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddIfOperation.

@Test
public void shouldAddIfOperation() throws SerialisationException {
    // Given
    final GetWalks getWalks = new GetWalks();
    final uk.gov.gchq.gaffer.operation.impl.Map map = new uk.gov.gchq.gaffer.operation.impl.Map();
    final ToVertices toVertices = new ToVertices();
    final ToSet toSet = new ToSet();
    final Exists exists = new Exists();
    final Limit limit = new Limit();
    final GetAllElements getAllElements = new GetAllElements();
    final GetElements getElements = new GetElements();
    final Conditional conditional = new Conditional();
    conditional.setPredicate(exists);
    final If ifOp = new If.Builder<>().conditional(conditional).then(getElements).otherwise(getAllElements).build();
    final AddOperationsToChain hook = new AddOperationsToChain();
    final Map<String, List<Operation>> after = new HashMap<>();
    final List<Operation> afterOps = new LinkedList<>();
    afterOps.add(ifOp);
    afterOps.add(limit);
    after.put("uk.gov.gchq.gaffer.operation.impl.output.ToSet", afterOps);
    hook.setAfter(after);
    final OperationChain opChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).build();
    // When
    hook.preExecute(opChain, new Context());
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).then(ifOp).then(limit).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : HashMap(java.util.HashMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) LinkedList(java.util.LinkedList) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) LinkedList(java.util.LinkedList) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) Map(java.util.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 13 with ToVertices

use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.

the class MapHandlerTest method shouldProcessWalksWithEdgeExtraction.

@Test
public void shouldProcessWalksWithEdgeExtraction() throws OperationException {
    // Given
    final Iterable<Walk> walks = Arrays.asList(walk, walk1);
    final Map<Iterable<Walk>, Iterable<Edge>> map = new Map.Builder<Iterable<Walk>>().input(walks).first(new IterableFunction.Builder<Walk>().first(new ExtractWalkEdgesFromHop(1)).then(new FirstItem<>()).build()).build();
    final ToVertices toVertices = new ToVertices.Builder().edgeVertices(ToVertices.EdgeVertices.SOURCE).build();
    final ToSet<Object> toSet = new ToSet<>();
    final OperationChain<Set<?>> opChain = new OperationChain.Builder().first(map).then(toVertices).then(toSet).build();
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    final OperationChainHandler<Set<?>> opChainHandler = new OperationChainHandler<>(opChainValidator, opChainOptimisers);
    given(store.handleOperation(map, context)).willReturn(Arrays.asList(EDGE_BC, EDGE_BD));
    given(store.handleOperation(toVertices, context)).willReturn(Arrays.asList("B", "B"));
    given(store.handleOperation(toSet, context)).willReturn(Sets.newHashSet("B", "B"));
    // When
    final Iterable<?> results = opChainHandler.doOperation(opChain, context, store);
    // Then
    assertThat((Iterable<String>) results).contains("B");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Set(java.util.Set) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) ExtractWalkEdgesFromHop(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) IterableFunction(uk.gov.gchq.koryphe.impl.function.IterableFunction) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 14 with ToVertices

use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.

the class MapHandlerTest method shouldProcessWalksInOperationChain.

@Test
public void shouldProcessWalksInOperationChain() throws OperationException {
    // Given
    final Iterable<Iterable<Set<Edge>>> walks = Arrays.asList(walk, walk1);
    final Map<Iterable<Iterable<Set<Edge>>>, Iterable<Edge>> map = new Map.Builder<Iterable<Iterable<Set<Edge>>>>().input(walks).first(new IterableFunction.Builder<Iterable<Set<Edge>>>().first(new FirstItem<>()).then(new FirstItem<>()).build()).build();
    final ToVertices toVertices = new ToVertices.Builder().edgeVertices(ToVertices.EdgeVertices.SOURCE).build();
    final ToSet<Object> toSet = new ToSet<>();
    final OperationChain<Set<?>> opChain = new OperationChain.Builder().first(map).then(toVertices).then(toSet).build();
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    final OperationChainHandler<Set<?>> opChainHandler = new OperationChainHandler<>(opChainValidator, opChainOptimisers);
    given(store.handleOperation(map, context)).willReturn(Arrays.asList(EDGE_AB, EDGE_CB));
    given(store.handleOperation(toVertices, context)).willReturn(Arrays.asList("A", "C"));
    given(store.handleOperation(toSet, context)).willReturn(Sets.newHashSet("A", "C"));
    // When
    final Iterable<?> results = opChainHandler.doOperation(opChain, context, store);
    // Then
    assertThat((Iterable<String>) results).containsOnly("A", "C");
}
Also used : ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Set(java.util.Set) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) IterableFunction(uk.gov.gchq.koryphe.impl.function.IterableFunction) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) Edge(uk.gov.gchq.gaffer.data.element.Edge) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)14 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)14 Context (uk.gov.gchq.gaffer.store.Context)12 List (java.util.List)11 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8 ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)3 Set (java.util.Set)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Map (uk.gov.gchq.gaffer.operation.impl.Map)2 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)2 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)2 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)2 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)2 IterableFunction (uk.gov.gchq.koryphe.impl.function.IterableFunction)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Walk (uk.gov.gchq.gaffer.data.graph.Walk)1 ExtractWalkEdgesFromHop (uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop)1