Search in sources :

Example 66 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class SampleDataForSplitPoints method validate.

@Override
public ValidationResult validate() {
    final ValidationResult result = Operation.super.validate();
    result.add(FieldUtil.validateRequiredFields(new Tuple3<>("proportionToSample must be greater than 0", proportionToSample, new IsMoreThan(0f))));
    return result;
}
Also used : Tuple3(uk.gov.gchq.koryphe.tuple.n.Tuple3) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 67 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan 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)

Example 68 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class GetDataFrameOfElementsHandlerTest method checkViewIsRespected.

@Test
public void checkViewIsRespected() throws OperationException {
    final Graph graph = getGraph("/schema-DataFrame/elements.json", getElements());
    // Edges group - check get correct edges
    GetDataFrameOfElements dfOperation = new GetDataFrameOfElements.Builder().view(new View.Builder().edge(EDGE_GROUP, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(800L)).build()).build()).build()).build();
    Dataset<Row> dataFrame = graph.execute(dfOperation, new User());
    Set<Row> results = new HashSet<>(dataFrame.collectAsList());
    final Set<Row> expectedRows = new HashSet<>();
    for (int i = 0; i < NUM_ELEMENTS; i++) {
        if (i * 200L > 800L) {
            final MutableList<Object> fields2 = new MutableList<>();
            fields2.appendElem(EDGE_GROUP);
            fields2.appendElem("" + i);
            fields2.appendElem("C");
            fields2.appendElem(true);
            fields2.appendElem(null);
            fields2.appendElem(6);
            fields2.appendElem(7);
            fields2.appendElem(8.0F);
            fields2.appendElem(9.0D);
            fields2.appendElem(10L);
            fields2.appendElem(i * 200L);
            expectedRows.add(Row$.MODULE$.fromSeq(fields2));
        }
    }
    assertEquals(expectedRows, results);
    // Entities group - check get correct entities
    dfOperation = new GetDataFrameOfElements.Builder().view(new View.Builder().entity(ENTITY_GROUP, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("property1").execute(new IsMoreThan(1)).build()).build()).build()).build();
    dataFrame = graph.execute(dfOperation, new User());
    results.clear();
    results.addAll(dataFrame.collectAsList());
    expectedRows.clear();
    for (int i = 2; i < NUM_ELEMENTS; i++) {
        final MutableList<Object> fields1 = new MutableList<>();
        fields1.clear();
        fields1.appendElem(ENTITY_GROUP);
        fields1.appendElem("" + i);
        fields1.appendElem(1);
        fields1.appendElem(i);
        fields1.appendElem(3.0F);
        fields1.appendElem(4.0D);
        fields1.appendElem(5L);
        fields1.appendElem(6);
        expectedRows.add(Row$.MODULE$.fromSeq(fields1));
    }
    assertEquals(expectedRows, results);
}
Also used : GetDataFrameOfElements(uk.gov.gchq.gaffer.spark.operation.dataframe.GetDataFrameOfElements) User(uk.gov.gchq.gaffer.user.User) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) MutableList(scala.collection.mutable.MutableList) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Row(org.apache.spark.sql.Row) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 69 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class AccumuloStoreRelationTest method testBuildScanRestrictViewByProperty.

@Test
public void testBuildScanRestrictViewByProperty() throws OperationException, StoreException {
    final List<TupleAdaptedPredicate<String, ?>> filters = new ArrayList<>();
    filters.add(new TupleAdaptedPredicate<>(new IsMoreThan(5, false), new String[] { "property1" }));
    final View view = new View.Builder().edge(GetDataFrameOfElementsHandlerTest.EDGE_GROUP, new ViewElementDefinition.Builder().postAggregationFilterFunctions(filters).build()).build();
    final Predicate<Element> returnElement = (Element element) -> element.getGroup().equals(GetDataFrameOfElementsHandlerTest.EDGE_GROUP) && (Integer) element.getProperty("property1") > 5;
    testBuildScanWithView("testBuildScanRestrictViewByProperty", view, returnElement);
}
Also used : TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 70 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class GetAdjacentIdsTest method shouldPassValidationOnEntitiesWithoutFilters.

@Test
public void shouldPassValidationOnEntitiesWithoutFilters() throws OperationException {
    // Given
    final Graph graph = GetAllElementsHandlerTest.getGraph();
    final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
    graph.execute(addElements, new User());
    // When
    final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).entity(GetAllElementsHandlerTest.BASIC_ENTITY, new ViewElementDefinition()).build()).build();
    final CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
    // Then
    final Set<EntityId> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    final Set<EntityId> expectedResults = new HashSet<>();
    GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> element.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
        final Edge edge = (Edge) element;
        return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("Y2") || edge.getDestination().equals("Y2");
    }).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 5).map(element -> {
        final Edge edge = (Edge) element;
        final Set<EntityId> nodes = new HashSet<>();
        nodes.add(new EntitySeed(edge.getSource()));
        nodes.add(new EntitySeed(edge.getDestination()));
        return nodes;
    }).flatMap(nodes -> nodes.stream()).forEach(expectedResults::add);
    expectedResults.remove(new EntitySeed("A"));
    expectedResults.remove(new EntitySeed("Y2"));
    assertEquals(expectedResults, resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Assertions.fail(org.junit.jupiter.api.Assertions.fail) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) User(uk.gov.gchq.gaffer.user.User) Set(java.util.Set) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) VERTEX_1(uk.gov.gchq.gaffer.mapstore.impl.VisibilityTest.VERTEX_1) Test(org.junit.jupiter.api.Test) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Graph(uk.gov.gchq.gaffer.graph.Graph) TestCase.assertTrue(junit.framework.TestCase.assertTrue) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Edge(uk.gov.gchq.gaffer.data.element.Edge) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Collections(java.util.Collections) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)72 Test (org.junit.jupiter.api.Test)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)40 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)34 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)24 Element (uk.gov.gchq.gaffer.data.element.Element)22 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)22 Edge (uk.gov.gchq.gaffer.data.element.Edge)20 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)20 User (uk.gov.gchq.gaffer.user.User)20 Graph (uk.gov.gchq.gaffer.graph.Graph)19 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)19 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)16 Entity (uk.gov.gchq.gaffer.data.element.Entity)16 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)13 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)13 Set (java.util.Set)12 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 OperationException (uk.gov.gchq.gaffer.operation.OperationException)12