Search in sources :

Example 11 with Aggregate

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);
}
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) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Test(org.junit.jupiter.api.Test)

Example 12 with Aggregate

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 13 with Aggregate

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);
}
Also used : Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Aggregations

Aggregate (uk.gov.gchq.gaffer.operation.impl.function.Aggregate)13 Test (org.junit.jupiter.api.Test)10 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 AggregatePair (uk.gov.gchq.gaffer.operation.util.AggregatePair)9 Element (uk.gov.gchq.gaffer.data.element.Element)6 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)5 Sum (uk.gov.gchq.koryphe.impl.binaryoperator.Sum)5 ArrayList (java.util.ArrayList)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)3 Context (uk.gov.gchq.gaffer.store.Context)2 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)2 Max (uk.gov.gchq.koryphe.impl.binaryoperator.Max)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)1 FederatedStoreProperties (uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties)1