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