use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan in project gaffer-doc by gchq.
the class IsLessThanExample method isLessThan5.
public void isLessThan5() {
// ---------------------------------------------------------
final IsLessThan function = new IsLessThan(5);
// ---------------------------------------------------------
runExample(function, null, 1, 1L, 5, 5L, 10, 10L, "1");
}
use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan in project Gaffer by gchq.
the class FilteringIT method testPostAggregationFilteringProperties.
@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.INGEST_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
// Given
final List<ElementId> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
final GetElements getElementsWithoutFiltering = new GetElements.Builder().input(seeds).build();
final GetElements getElementsWithFiltering = new GetElements.Builder().input(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(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
List<Element> expectedResults = Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A3"), getEntity("A5"), getEntity("B5"));
ElementUtil.assertElementEquals(expectedResults, resultsWithoutFiltering);
// Then - with filtering
List<Element> expectedFilteredResults = Arrays.asList(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEdge("A3", "A3", true), getEdge("A3", "B3", true), getEdge("A3", "C3", true), getEdge("A3", "D3", true), getEntity("A5"));
ElementUtil.assertElementEquals(expectedFilteredResults, resultsWithFiltering);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan in project Gaffer by gchq.
the class RoadTrafficTestQueries method checkRoadJunctionsInSouthWestHeavilyUsedByBusesIn2000.
@Test
public void checkRoadJunctionsInSouthWestHeavilyUsedByBusesIn2000() throws OperationException, ParseException {
assumeTrue(this.graph.hasTrait(StoreTrait.QUERY_AGGREGATION), "Skipping test as the store does not implement required trait.");
assumeTrue(this.graph.hasTrait(StoreTrait.TRANSFORMATION), "Skipping test as the store does not implement required trait.");
assumeTrue(this.graph.hasTrait(StoreTrait.PRE_AGGREGATION_FILTERING), "Skipping test as the store does not implement required trait.");
assumeTrue(this.graph.hasTrait(StoreTrait.POST_AGGREGATION_FILTERING), "Skipping test as the store does not implement required trait.");
assertNotNull(this.graph, "graph is null");
final Date JAN_01_2000 = new SimpleDateFormat("yyyy-MM-dd").parse("2000-01-01");
final Date JAN_01_2001 = new SimpleDateFormat("yyyy-MM-dd").parse("2001-01-01");
final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_2000, true)).select("endDate").execute(new IsLessThan(JAN_01_2001, false)).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
Set<String> resultSet = new HashSet<>();
final Iterable<? extends String> results = this.graph.execute(opChain, this.user);
for (final String r : results) {
resultSet.add(r);
}
assertEquals(SW_ROAD_JUNCTIONS_WITH_HEAVY_BUS_USAGE_IN_2000, resultSet);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan in project Gaffer by gchq.
the class JavaPredicateToParquetPredicate method getPrimitiveFilter.
public FilterPredicate getPrimitiveFilter(final Predicate filterFunction, final String selection, final String group, final SchemaUtils schemaUtils) throws SerialisationException {
// All supported filters will be in the if else statement below
if (filterFunction instanceof IsEqual) {
final IsEqual isEqual = (IsEqual) filterFunction;
final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isEqual.getControlValue());
return getIsEqualFilter(selection, parquetObjects, group, schemaUtils);
} else if (filterFunction instanceof IsLessThan) {
final IsLessThan isLessThan = (IsLessThan) filterFunction;
final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isLessThan.getControlValue());
if (isLessThan.getOrEqualTo()) {
return getIsLessThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
}
return getIsLessThanFilter(selection, parquetObjects, group, schemaUtils);
} else if (filterFunction instanceof IsMoreThan) {
final IsMoreThan isMoreThan = (IsMoreThan) filterFunction;
final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isMoreThan.getControlValue());
if (isMoreThan.getOrEqualTo()) {
return getIsMoreThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
}
return getIsMoreThanFilter(selection, parquetObjects, group, schemaUtils);
} else if (filterFunction instanceof IsTrue) {
return eq(booleanColumn(selection), true);
} else if (filterFunction instanceof IsFalse) {
return eq(booleanColumn(selection), false);
} else {
fullyApplied = false;
LOGGER.warn(filterFunction.getClass().getCanonicalName() + " is not a natively supported filter by the Parquet store, therefore execution will take longer to perform this filter.");
return null;
}
}
use of uk.gov.gchq.koryphe.impl.predicate.IsLessThan in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithPreFiltering_2.
@Test
@TraitRequirement(StoreTrait.POST_AGGREGATION_FILTERING)
public void shouldGetPathsWithPreFiltering_2() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final OperationChain operationChain = new OperationChain.Builder().first(new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsLessThan(3)).build()).build()).build()).build()).then(operation).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(operationChain, operationChain).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("ABC");
}
Aggregations