use of uk.gov.gchq.gaffer.function.filter.IsLessThan in project Gaffer by gchq.
the class IsLessThanExample method isLessThan5.
public void isLessThan5() {
// ---------------------------------------------------------
final IsLessThan function = new IsLessThan(5);
// ---------------------------------------------------------
runExample(function, 1, 1L, 5, 5L, 10, 10L, "1");
}
use of uk.gov.gchq.gaffer.function.filter.IsLessThan in project Gaffer by gchq.
the class IsLessThanExample method isLessThanALong5.
public void isLessThanALong5() {
// ---------------------------------------------------------
final IsLessThan function = new IsLessThan(5L);
// ---------------------------------------------------------
runExample(function, 1, 1L, 5, 5L, 10, 10L, "1");
}
use of uk.gov.gchq.gaffer.function.filter.IsLessThan in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifySourceOrDestinationAndPropertyFilter.
@Test
public void testSpecifySourceOrDestinationAndPropertyFilter() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testSpecifyVertexAndPropertyFilter");
// Specify src and a filter on property1
Filter[] filters = new Filter[2];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.SRC_COL_NAME, "0");
FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, operation.getView().getEntityGroups().size());
assertEquals(2, operation.getView().getEdgeGroups().size());
final Set<EntitySeed> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getSeeds()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
View opView = operation.getView();
for (final String edgeGroup : EDGE_GROUPS) {
final List<ConsumerFunctionContext<String, FilterFunction>> edgePostAggFilters = opView.getEdge(edgeGroup).getPostAggregationFilterFunctions();
assertEquals(1, edgePostAggFilters.size());
assertEquals(new ArrayList<>(Collections.singleton("property1")), edgePostAggFilters.get(0).getSelection());
assertEquals(new IsMoreThan(5, false), edgePostAggFilters.get(0).getFunction());
}
// Specify src and filters on property1 and property4
filters = new Filter[3];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.SRC_COL_NAME, "0");
filters[2] = new LessThan("property4", 8);
converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, operation.getView().getEntityGroups().size());
assertEquals(1, operation.getView().getEdgeGroups().size());
seeds.clear();
for (final Object seed : ((GetRDDOfElements) operation).getSeeds()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
opView = operation.getView();
final List<ConsumerFunctionContext<String, FilterFunction>> entityPostAggFilters = opView.getEdge(EDGE_GROUP).getPostAggregationFilterFunctions();
assertEquals(2, entityPostAggFilters.size());
final List<String> expectedProperties = new ArrayList<>();
expectedProperties.add("property1");
expectedProperties.add("property4");
assertEquals(1, entityPostAggFilters.get(0).getSelection().size());
assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection().get(0));
assertEquals(new IsMoreThan(5, false), entityPostAggFilters.get(0).getFunction());
assertEquals(1, entityPostAggFilters.get(1).getSelection().size());
assertEquals(expectedProperties.get(1), entityPostAggFilters.get(1).getSelection().get(0));
assertEquals(new IsLessThan(8, false), entityPostAggFilters.get(1).getFunction());
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.function.filter.IsLessThan in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifyMultiplePropertyFilters.
@Test
public void testSpecifyMultiplePropertyFilters() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testSpecifyMultiplePropertyFilters");
final Filter[] filters = new Filter[2];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new LessThan("property4", 8L);
FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfAllElements);
// Only groups ENTITY_GROUP and EDGE_GROUP should be in the view as only they have property1 and property4
View opView = operation.getView();
List<ConsumerFunctionContext<String, FilterFunction>> entityPostAggFilters = opView.getEntity(ENTITY_GROUP).getPostAggregationFilterFunctions();
assertEquals(2, entityPostAggFilters.size());
final ArrayList<String> expectedProperties = new ArrayList<>();
expectedProperties.add("property1");
expectedProperties.add("property4");
assertEquals(1, entityPostAggFilters.get(0).getSelection().size());
assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection().get(0));
assertEquals(1, entityPostAggFilters.get(1).getSelection().size());
assertEquals(expectedProperties.get(1), entityPostAggFilters.get(1).getSelection().get(0));
final ArrayList<FilterFunction> expectedFunctions = new ArrayList<>();
expectedFunctions.add(new IsMoreThan(5, false));
expectedFunctions.add(new IsLessThan(8L, false));
assertEquals(expectedFunctions.get(0), entityPostAggFilters.get(0).getFunction());
assertEquals(expectedFunctions.get(1), entityPostAggFilters.get(1).getFunction());
final List<ConsumerFunctionContext<String, FilterFunction>> edgePostAggFilters = opView.getEdge(EDGE_GROUP).getPostAggregationFilterFunctions();
assertEquals(2, edgePostAggFilters.size());
assertEquals(1, edgePostAggFilters.get(0).getSelection().size());
assertEquals(expectedProperties.get(0), edgePostAggFilters.get(0).getSelection().get(0));
assertEquals(1, edgePostAggFilters.get(1).getSelection().size());
assertEquals(expectedProperties.get(1), edgePostAggFilters.get(1).getSelection().get(0));
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.function.filter.IsLessThan in project Gaffer by gchq.
the class FilteringIT method testFilteringProperties.
@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() throws OperationException {
// Given
final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
// When - without filtering
final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
// When - with filtering
final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
// Then - without filtering
assertNotNull(resultsWithoutFiltering);
assertEquals(8, resultsWithoutFiltering.size());
assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
// Then - with filtering
assertNotNull(resultsWithFiltering);
assertEquals(6, resultsWithFiltering.size());
assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
Aggregations