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;
}
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;
}
}
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);
}
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);
}
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);
}
Aggregations