Search in sources :

Example 1 with Aggregate

use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project gaffer-doc by gchq.

the class AggregateExample method aggregateOnlyEdgesOfTypeEdgeWithATransientPropertyAndProvidedAggregator.

public void aggregateOnlyEdgesOfTypeEdgeWithATransientPropertyAndProvidedAggregator() {
    // ---------------------------------------------------------
    final String[] groupBy = {};
    final Aggregate aggregate = new Aggregate.Builder().edge("edge", new AggregatePair(groupBy, new ElementAggregator.Builder().select("transientProperty1").execute(new StringConcat()).build())).build();
    // ---------------------------------------------------------
    showExample(aggregate, "The groupBy has been set to an empty array. This will override the groupBy value in the schema.");
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate)

Example 2 with Aggregate

use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.

the class FederatedAggregateHandlerTest method shouldDelegateToHandler.

@Test
public void shouldDelegateToHandler() throws OperationException {
    // Given
    final FederatedStore store = mock(FederatedStore.class);
    final AggregateHandler handler = mock(AggregateHandler.class);
    final Aggregate op = mock(Aggregate.class);
    final Context context = mock(Context.class);
    final Iterable expectedResult = mock(Iterable.class);
    final Schema schema = mock(Schema.class);
    given(store.getSchema(op, context)).willReturn(schema);
    given(handler.doOperation(op, schema)).willReturn(expectedResult);
    final FederatedAggregateHandler federatedHandler = new FederatedAggregateHandler(handler);
    // When
    final Object result = federatedHandler.doOperation(op, context, store);
    // Then
    assertSame(expectedResult, result);
    verify(handler).doOperation(op, schema);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AggregateHandler(uk.gov.gchq.gaffer.store.operation.handler.function.AggregateHandler) FederatedAggregateHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedAggregateHandler) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) FederatedAggregateHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedAggregateHandler) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 3 with Aggregate

use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.

the class FederatedAggregateHandlerTest method shouldAggregateDuplicatesFromDiffStores.

@Test
public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
    FederatedStoreProperties federatedStoreProperties = FederatedStoreProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "predefinedFederatedStore.properties"));
    final Graph fed = new Graph.Builder().config(new GraphConfig("fed")).addSchema(new Schema()).storeProperties(federatedStoreProperties).build();
    final String graphNameA = "a";
    final String graphNameB = "b";
    final Context context = new Context(new User());
    fed.execute(new OperationChain.Builder().first(new AddGraph.Builder().graphId(graphNameA).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).then(new AddGraph.Builder().graphId(graphNameB).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).build(), context);
    fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameA).build(), context);
    fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameB).build(), context);
    final CloseableIterable<? extends Element> getAll = fed.execute(new GetAllElements(), context);
    List<Element> list = new ArrayList<>();
    getAll.forEach(list::add);
    assertThat(list).hasSize(2);
    final Iterable<? extends Element> getAggregate = fed.execute(new OperationChain.Builder().first(new GetAllElements()).then(new Aggregate()).build(), context);
    list.clear();
    getAggregate.forEach(list::add);
    assertThat(list).hasSize(1);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) FederatedStoreProperties(uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Test(org.junit.jupiter.api.Test)

Example 4 with Aggregate

use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.

the class ViewMigration method createMigrationOps.

public static List<Operation> createMigrationOps(final boolean aggregateAfter, final Iterable<ViewMigration> views) {
    final ViewMigration viewMig = new ViewMigration(aggregateAfter);
    for (final ViewMigration view : views) {
        viewMig.edgesPostAggregationFilter.putAll(view.edgesPostAggregationFilter);
        viewMig.entitiesPostAggregationFilter.putAll(view.entitiesPostAggregationFilter);
        viewMig.edgesPostTransformFilter.putAll(view.edgesPostTransformFilter);
        viewMig.entitiesPostTransformFilter.putAll(view.entitiesPostTransformFilter);
        viewMig.edgesTransformer.putAll(view.edgesTransformer);
        viewMig.entitiesTransformer.putAll(view.entitiesTransformer);
    }
    final List<Operation> updatedOps = new ArrayList<>();
    if (aggregateAfter) {
        final Aggregate aggregate = new Aggregate();
        updatedOps.add(aggregate);
        if (!viewMig.entitiesPostAggregationFilter.isEmpty() || !viewMig.edgesPostAggregationFilter.isEmpty()) {
            final Filter postAggregationFilter = new Filter.Builder().entities(viewMig.entitiesPostAggregationFilter).edges(viewMig.edgesPostAggregationFilter).build();
            updatedOps.add(postAggregationFilter);
        }
        if (!viewMig.entitiesTransformer.isEmpty() || !viewMig.edgesTransformer.isEmpty()) {
            final Transform transformFunction = new Transform.Builder().entities(viewMig.entitiesTransformer).edges(viewMig.edgesTransformer).build();
            updatedOps.add(transformFunction);
        }
        if (!viewMig.edgesPostTransformFilter.isEmpty() || !viewMig.entitiesPostTransformFilter.isEmpty()) {
            final Filter postTransformFilter = new Filter.Builder().entities(viewMig.entitiesPostTransformFilter).edges(viewMig.edgesPostTransformFilter).build();
            updatedOps.add(postTransformFilter);
        }
    }
    return updatedOps;
}
Also used : Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) TransformAndFilter(uk.gov.gchq.gaffer.graph.hook.migrate.predicate.TransformAndFilter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform)

Example 5 with Aggregate

use of uk.gov.gchq.gaffer.operation.impl.function.Aggregate in project Gaffer by gchq.

the class AggregateHandlerTest method shouldFailValidationWhenSchemaElementDefinitionsAreNull.

@Test
public void shouldFailValidationWhenSchemaElementDefinitionsAreNull() {
    // Given
    given(store.getSchema()).willReturn(new Schema());
    input.add(edge);
    input.add(edge1);
    edges.put(TestGroups.EDGE, new AggregatePair());
    final Aggregate aggregate = new Aggregate.Builder().input(input).edges(edges).build();
    // When / Then
    try {
        final Iterable<? extends Element> results = handler.doOperation(aggregate, context, store);
    } catch (final OperationException e) {
        assertTrue(e.getMessage().contains("Edge group: " + TestGroups.EDGE + " does not exist in the schema."));
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) OperationException(uk.gov.gchq.gaffer.operation.OperationException) 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