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