use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.
the class AggregateHandlerTest method shouldAggregateElementsWhenAggregatorNotProvidedInSchema.
@Test
public void shouldAggregateElementsWhenAggregatorNotProvidedInSchema() throws OperationException {
// Given
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().groupBy("timestamp").build()).build();
given(store.getSchema()).willReturn(schema);
input.add(entity);
input.add(entity1);
input.add(entity2);
input.add(entity3);
final AggregatePair pair = new AggregatePair(new ElementAggregator.Builder().select("count").execute(new Sum()).build());
entities.put(TestGroups.ENTITY, pair);
final Entity expectedEntity = new Entity.Builder().group(TestGroups.ENTITY).property("timestamp", 3L).property("count", 5).build();
final Entity expectedEntity1 = new Entity.Builder().group(TestGroups.ENTITY).property("timestamp", 2L).property("count", 6).build();
expected.add(expectedEntity);
expected.add(expectedEntity1);
final Aggregate aggregate = new Aggregate.Builder().input(input).entities(entities).build();
// When
final Iterable<? extends Element> results = handler.doOperation(aggregate, context, store);
final Set<Element> resultsSet = Sets.newHashSet(results);
// Then
assertEquals(expected, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.
the class AggregateHandlerTest method shouldAggregateAMixOfEdgesAndEntities.
@Test
public void shouldAggregateAMixOfEdgesAndEntities() throws OperationException {
// Given
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().aggregator(new ElementAggregator.Builder().select("turns").execute(new Max()).build()).build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().aggregator(new ElementAggregator.Builder().select("count").execute(new Sum()).build()).build()).build();
given(store.getSchema()).willReturn(schema);
input.add(edge);
input.add(edge1);
input.add(edge2);
input.add(entity);
input.add(entity1);
input.add(entity2);
input.add(entity3);
final AggregatePair edgePair = new AggregatePair(new String[] { "timestamp" });
final AggregatePair entityPair = new AggregatePair(new String[] { "timestamp" });
edges.put(TestGroups.EDGE, edgePair);
entities.put(TestGroups.ENTITY, entityPair);
final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).property("timestamp", 2L).property("turns", 6).property("count", 2L).build();
final Edge expectedEdge1 = new Edge.Builder().group(TestGroups.EDGE).property("timestamp", 1L).property("turns", 9).property("count", 5L).build();
final Entity expectedEntity = new Entity.Builder().group(TestGroups.ENTITY).property("timestamp", 2L).property("count", 6).build();
final Entity expectedEntity1 = new Entity.Builder().group(TestGroups.ENTITY).property("timestamp", 3L).property("count", 5).build();
expected.add(expectedEdge);
expected.add(expectedEdge1);
expected.add(expectedEntity);
expected.add(expectedEntity1);
final Aggregate aggregate = new Aggregate.Builder().input(input).edges(edges).entities(entities).build();
// When
final Iterable<? extends Element> results = handler.doOperation(aggregate, context, store);
final Set<Element> resultsSet = Sets.newHashSet(results);
// Then
assertEquals(expected, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.
the class AggregateHandlerTest method shouldAggregateEdgesFromMultipleGroups.
@Test
public void shouldAggregateEdgesFromMultipleGroups() throws OperationException {
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().aggregator(new ElementAggregator.Builder().select("turns").execute(new Max()).build()).groupBy("timestamp").build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().aggregator(new ElementAggregator.Builder().select("count").execute(new Sum()).select("length").execute(new Sum()).build()).groupBy("timestamp").build()).build();
given(store.getSchema()).willReturn(schema);
input.add(edge);
input.add(edge1);
input.add(edge2);
input.add(edge3);
input.add(edge4);
final AggregatePair pair = new AggregatePair();
final AggregatePair pair1 = new AggregatePair();
edges.put(TestGroups.EDGE, pair);
edges.put(TestGroups.EDGE_2, pair1);
final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).property("timestamp", 2L).property("turns", 6).property("count", 2L).build();
final Edge expectedEdge1 = new Edge.Builder().group(TestGroups.EDGE).property("timestamp", 1L).property("turns", 9).property("count", 5L).build();
final Edge expectedEdge2 = new Edge.Builder().group(TestGroups.EDGE_2).property("timestamp", 4L).property("length", 40).property("count", 5L).build();
expected.add(expectedEdge);
expected.add(expectedEdge1);
expected.add(expectedEdge2);
final Aggregate aggregate = new Aggregate.Builder().input(input).edges(edges).build();
// When
final Iterable<? extends Element> results = handler.doOperation(aggregate, context, store);
final Set<Element> resultsSet = Sets.newHashSet(results);
// Then
assertEquals(expected, resultsSet);
}
Aggregations