use of uk.gov.gchq.gaffer.operation.impl.function.Filter in project Gaffer by gchq.
the class FilterHandlerTest method shouldApplyGlobalFilterAndReturnOnlySpecifiedEdges.
@Test
public void shouldApplyGlobalFilterAndReturnOnlySpecifiedEdges() throws OperationException {
// Given
given(store.getSchema()).willReturn(SCHEMA);
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 2L).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE_2).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 1L).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE_2).source("junctionB").dest("junctionA").directed(true).property(TestPropertyNames.COUNT, 4L).build();
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.COUNT, 3L).build();
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY_2).property(TestPropertyNames.COUNT, 4L).build();
input.add(edge);
input.add(edge1);
input.add(edge2);
input.add(entity);
input.add(entity1);
expected.add(edge2);
final Filter filter = new Filter.Builder().input(input).globalElements(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(2L)).build()).edge(TestGroups.EDGE_2).build();
// When
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
// Then
final List<Element> resultsList = Lists.newArrayList(results);
assertEquals(expected, resultsList);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Filter in project Gaffer by gchq.
the class FilterHandlerTest method shouldFilterInputBasedOnGroupAndCount.
@Test
public void shouldFilterInputBasedOnGroupAndCount() throws OperationException {
// Given
given(store.getSchema()).willReturn(SCHEMA);
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 2L).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 1L).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("junctionB").dest("junctionA").directed(true).property(TestPropertyNames.COUNT, 4L).build();
final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE_2).source("junctionC").dest("junctionD").directed(true).property(TestPropertyNames.COUNT, 3L).build();
input.add(edge);
input.add(edge1);
input.add(edge2);
input.add(edge3);
expected.add(edge);
expected.add(edge2);
final Filter filter = new Filter.Builder().input(input).edge(TestGroups.EDGE, new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(1L)).build()).build();
// When
final Iterable<? extends Element> result = handler.doOperation(filter, context, store);
// Then
final List<Element> resultList = Streams.toStream(result).collect(Collectors.toList());
assertEquals(expected, resultList);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Filter in project Gaffer by gchq.
the class FilterHandlerTest method shouldFilterBasedOnAdjacentMatchedVertex.
@Test
public void shouldFilterBasedOnAdjacentMatchedVertex() throws OperationException {
// Given
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("vertex").destination("vertex").property(TestPropertyNames.COUNT, "count.long").build()).type("vertex", new TypeDefinition(String.class)).type("count.long", new TypeDefinition(Long.class)).build();
given(store.getSchema()).willReturn(schema);
final Filter filter = new Filter.Builder().input(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal2").dest("destVal2").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal4").dest("destVal4").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build()).edge(TestGroups.EDGE, new ElementFilter.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new IsIn("destVal1", "srcVal3")).build()).build();
// When
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
// Then
ElementUtil.assertElementEquals(Arrays.asList(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.SOURCE).build()), results);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Filter in project Gaffer by gchq.
the class FilterHandlerTest method shouldFilterBasedOnMatchedVertex.
@Test
public void shouldFilterBasedOnMatchedVertex() throws OperationException {
// Given
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("vertex").destination("vertex").property(TestPropertyNames.COUNT, "count.long").build()).type("vertex", new TypeDefinition(String.class)).type("count.long", new TypeDefinition(Long.class)).build();
given(store.getSchema()).willReturn(schema);
final Filter filter = new Filter.Builder().input(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal2").dest("destVal2").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal4").dest("destVal4").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build()).edge(TestGroups.EDGE, new ElementFilter.Builder().select(IdentifierType.MATCHED_VERTEX.name()).execute(new IsIn("srcVal1", "destVal3")).build()).build();
// When
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
// Then
ElementUtil.assertElementEquals(Arrays.asList(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.SOURCE).build()), results);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Filter in project Gaffer by gchq.
the class FilterHandlerTest method shouldReturnAllValuesWithNullElementFilters.
@Test
public void shouldReturnAllValuesWithNullElementFilters() throws OperationException {
// Given
given(store.getSchema()).willReturn(SCHEMA);
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 2L).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").directed(true).property(TestPropertyNames.COUNT, 1L).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("junctionB").dest("junctionA").directed(true).property(TestPropertyNames.COUNT, 4L).build();
input.add(edge);
input.add(edge1);
input.add(edge2);
expected.add(edge);
expected.add(edge1);
expected.add(edge2);
final Filter filter = new Filter.Builder().input(input).build();
// When
final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
// Then
final List<Element> resultsList = Lists.newArrayList(results);
assertEquals(expected, resultsList);
}
Aggregations