Search in sources :

Example 16 with IsMoreThan

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

the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter.

@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter() throws OperationException {
    // Given
    final Graph graph = getGraph();
    final AddElements addElements = new AddElements.Builder().input(getElements()).build();
    graph.execute(addElements, new User());
    // When
    final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
    final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
    // Then
    final Set<Element> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    final Set<Element> expectedResults = new HashSet<>();
    getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) Graph(uk.gov.gchq.gaffer.graph.Graph) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with IsMoreThan

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

the class ElementFilterTest method shouldExecuteOrPredicates.

@Test
public void shouldExecuteOrPredicates() {
    final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Or.Builder<>().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some value")).build()).build();
    final Entity element1 = makeEntity(3, "some value");
    final Entity element2 = makeEntity(1, "some value");
    final Entity element3 = makeEntity(3, "some invalid value");
    final Entity element4 = makeEntity(1, "some invalid value");
    // When
    final boolean result1 = filter.test(element1);
    final boolean result2 = filter.test(element2);
    final boolean result3 = filter.test(element3);
    final boolean result4 = filter.test(element4);
    // Then
    assertTrue(result1);
    assertTrue(result2);
    assertTrue(result3);
    assertFalse(result4);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Or(uk.gov.gchq.koryphe.impl.predicate.Or) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 18 with IsMoreThan

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

the class ElementFilterTest method shouldExecuteNotPredicates.

@Test
public void shouldExecuteNotPredicates() {
    final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Not<>(new Or.Builder<>().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some value")).build())).build();
    final Entity element1 = makeEntity(3, "some value");
    final Entity element2 = makeEntity(1, "some value");
    final Entity element3 = makeEntity(3, "some invalid value");
    final Entity element4 = makeEntity(1, "some invalid value");
    // When
    final boolean result1 = filter.test(element1);
    final boolean result2 = filter.test(element2);
    final boolean result3 = filter.test(element3);
    final boolean result4 = filter.test(element4);
    // Then
    assertFalse(result1);
    assertFalse(result2);
    assertFalse(result3);
    assertTrue(result4);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Not(uk.gov.gchq.koryphe.impl.predicate.Not) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 19 with IsMoreThan

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

the class Queries method runFullExample.

private void runFullExample(final Graph graph, final User user) throws OperationException {
    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", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).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 Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
    final Iterable<? extends String> results = graph.execute(opChain, user);
    System.out.println("Full example results:");
    for (final String result : results) {
        System.out.println(result);
    }
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) FreqMapExtractor(uk.gov.gchq.gaffer.types.function.FreqMapExtractor) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) InDateRangeDual(uk.gov.gchq.koryphe.impl.predicate.range.InDateRangeDual) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 20 with IsMoreThan

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

the class ViewValidatorTest method shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties.

@Test
public void shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Or.Builder().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some other value")).build()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertFalse(result.isValid());
}
Also used : Or(uk.gov.gchq.koryphe.impl.predicate.Or) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) 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