Search in sources :

Example 26 with IsEqual

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);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 27 with IsEqual

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) List(java.util.List) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 28 with IsEqual

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");
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 29 with IsEqual

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");
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 30 with IsEqual

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;
    }
}
Also used : IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual)

Aggregations

IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)20 Test (org.junit.jupiter.api.Test)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)16 Element (uk.gov.gchq.gaffer.data.element.Element)12 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)10 Test (org.junit.Test)7 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)7 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)7 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)6 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)6 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)6 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)6 Or (uk.gov.gchq.koryphe.impl.predicate.Or)6 Graph (uk.gov.gchq.gaffer.graph.Graph)5 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)4 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)4 User (uk.gov.gchq.gaffer.user.User)4