Search in sources :

Example 1 with Product

use of uk.gov.gchq.koryphe.impl.binaryoperator.Product in project Gaffer by gchq.

the class AggregatorUtilTest method shouldQueryAggregateElementsWithGroupByAndViewAggregator.

@Test
public void shouldQueryAggregateElementsWithGroupByAndViewAggregator() {
    // given
    final Schema schema = Schema.fromJson(StreamUtil.openStreams(getClass(), "schema-groupby"));
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().aggregator(new ElementAggregator.Builder().select("count").execute(new Product()).build()).build()).entity(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final List<Element> elements = Arrays.asList(new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex1").property("count", 1).property("property2", "value1").property("visibility", "vis1").build(), new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex1").property("count", 2).property("property2", "value1").property("visibility", "vis2").build(), new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex1").property("count", 2).property("property2", "value2").property("visibility", "vis1").build(), new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex1").property("count", 10).property("property2", "value2").property("visibility", "vis2").build(), new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex2").property("count", 20).property("property2", "value10").property("visibility", "vis1").build(), new Edge.Builder().group(TestGroups.EDGE).source("vertex2").dest("vertex1").property("count", 100).property("property2", "value1").property("visibility", "vis1").build(), new Edge.Builder().group(TestGroups.EDGE).source("vertex2").dest("vertex1").property("count", 200).property("property2", "value1").property("visibility", "vis2").build(), new Edge.Builder().group(TestGroups.EDGE).source("vertex2").dest("vertex1").property("count", 1000).property("property2", "value2").property("visibility", "vis1").build(), new Edge.Builder().group(TestGroups.EDGE).source("vertex2").dest("vertex1").property("count", 2000).property("property2", "value2").property("visibility", "vis2").build());
    final Set<Element> expected = Sets.newHashSet(new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex1").property("count", 40).property("property2", "value1").property("visibility", "vis1").build(), new Entity.Builder().group(TestGroups.ENTITY).vertex("vertex2").property("count", 20).property("property2", "value10").property("visibility", "vis1").build(), new Edge.Builder().group(TestGroups.EDGE).source("vertex2").dest("vertex1").property("count", 3300).property("property2", "value1").property("visibility", "vis1").build());
    // when
    final CloseableIterable<Element> aggregatedElements = AggregatorUtil.queryAggregate(elements, schema, view);
    // then
    assertElementEquals(expected, aggregatedElements);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) Product(uk.gov.gchq.koryphe.impl.binaryoperator.Product) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SchemaTest(uk.gov.gchq.gaffer.store.schema.SchemaTest) Test(org.junit.jupiter.api.Test)

Example 2 with Product

use of uk.gov.gchq.koryphe.impl.binaryoperator.Product in project Gaffer by gchq.

the class AggregationIT method shouldGetAllElementsWithFilterSummarisation.

@Test
@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.QUERY_AGGREGATION })
public void shouldGetAllElementsWithFilterSummarisation() throws Exception {
    final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
    edge1.putProperty(TestPropertyNames.INT, 100);
    edge1.putProperty(TestPropertyNames.COUNT, 1L);
    final Edge edge2 = edge1.emptyClone();
    edge2.putProperty(TestPropertyNames.INT, 101);
    edge2.putProperty(TestPropertyNames.COUNT, 1L);
    graph.execute(new AddElements.Builder().input(edge1, edge2).build(), getUser());
    final GetAllElements op = new GetAllElements.Builder().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList(100, 101))).build()).groupBy().aggregator(new ElementAggregator.Builder().select(TestPropertyNames.INT).execute(new Product()).build()).build()).build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> resultList = Lists.newArrayList(results);
    assertThat(resultList).hasSize(1);
    // aggregation is has been replaced with Product
    assertThat(resultList.get(0).getProperty(TestPropertyNames.INT)).isEqualTo(10100);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Element(uk.gov.gchq.gaffer.data.element.Element) Product(uk.gov.gchq.koryphe.impl.binaryoperator.Product) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)2 Product (uk.gov.gchq.koryphe.impl.binaryoperator.Product)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 SchemaTest (uk.gov.gchq.gaffer.store.schema.SchemaTest)1 IsIn (uk.gov.gchq.koryphe.impl.predicate.IsIn)1