use of uk.gov.gchq.koryphe.impl.predicate.IsEqual 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.IsEqual in project Gaffer by gchq.
the class FederatedStoreSchemaTest method shouldBeAbleToFilterPropertyWithOverlappingSchemas.
@Test
public void shouldBeAbleToFilterPropertyWithOverlappingSchemas() throws OperationException {
// Given
addOverlappingPropertiesGraphs(STRING_TYPE);
// Element 1
fStore.execute(new AddElements.Builder().input(new Edge.Builder().group("e1").source("source1").dest("dest1").property("prop1", "value1").property("prop2", "value2").build()).build(), testContext);
// Element 2
fStore.execute(new AddElements.Builder().input(new Edge.Builder().group("e1").source("source1").dest("dest2").property("prop1", "value1").property("prop2", "value2").build()).build(), testContext);
// When
final CloseableIterable<? extends Element> elements = fStore.execute(new GetElements.Builder().input(new EntitySeed("source1")).view(new View.Builder().edge("e1", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("prop2").execute(new IsEqual("value2")).build()).build()).build()).build(), testContext);
assertNotNull(elements);
final List results = Streams.toStream(elements).collect(Collectors.toList());
// Then
HashSet<Edge> expected = new HashSet<>();
// Graph b, element 1
expected.add(new Edge.Builder().group("e1").source("source1").dest("dest1").matchedVertex(EdgeId.MatchedVertex.SOURCE).property("prop1", "value1").property("prop2", "value2").build());
// Graph b, element 2
expected.add(new Edge.Builder().group("e1").source("source1").dest("dest2").matchedVertex(EdgeId.MatchedVertex.SOURCE).property("prop1", "value1").property("prop2", "value2").build());
assertThat(results).containsExactlyInAnyOrderElementsOf(expected);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class AbstractOperationsTest method shouldThrowUnsupportedTraitExceptionWithPostAggregationFiltering.
@Test
public void shouldThrowUnsupportedTraitExceptionWithPostAggregationFiltering() throws OperationException {
// Given
final Graph graph = createGraph();
final List<Element> elements = getInputDataForGetAllElementsTest();
graph.execute(new AddElements.Builder().input(elements).build(), user);
final View view = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("double").execute(new IsEqual(2.0)).build()).build()).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> graph.execute(new GetElements.Builder().input(new EmptyClosableIterable<>()).view(view).build(), user)).withMessageContaining("POST_AGGREGATION_FILTERING");
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class AbstractOperationsTest method shouldThrowUnsupportedTraitExceptionWithPostTransformFiltering.
@Test
public void shouldThrowUnsupportedTraitExceptionWithPostTransformFiltering() throws OperationException {
// Given
final Graph graph = createGraph();
final List<Element> elements = getInputDataForGetAllElementsTest();
graph.execute(new AddElements.Builder().input(elements).build(), user);
final View view = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postTransformFilter(new ElementFilter.Builder().select("double").execute(new IsEqual(2.0)).build()).build()).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> graph.execute(new GetElements.Builder().input(new EmptyClosableIterable<>()).view(view).build(), user)).withMessageContaining("POST_TRANSFORMATION_FILTERING");
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual 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;
}
}
Aggregations