use of uk.gov.gchq.koryphe.impl.binaryoperator.Max in project Gaffer by gchq.
the class AccumuloStore method validateSchema.
@Override
protected void validateSchema(final ValidationResult validationResult, final Serialiser serialiser) {
super.validateSchema(validationResult, serialiser);
final String timestampProperty = getSchema().getConfig(AccumuloStoreConstants.TIMESTAMP_PROPERTY);
if (null != timestampProperty) {
final Iterable<SchemaElementDefinition> defs = new ChainedIterable<>(getSchema().getEntities().values(), getSchema().getEdges().values());
for (final SchemaElementDefinition def : defs) {
final TypeDefinition typeDef = def.getPropertyTypeDef(timestampProperty);
if (null != typeDef && null != typeDef.getAggregateFunction() && !(typeDef.getAggregateFunction() instanceof Max)) {
validationResult.addError("The aggregator for the " + timestampProperty + " property must be set to: " + Max.class.getName() + " this cannot be overridden for this Accumulo Store, as you have told Accumulo to store this property in the timestamp column.");
}
}
}
}
use of uk.gov.gchq.koryphe.impl.binaryoperator.Max in project Gaffer by gchq.
the class ViewElementDefinitionTest method shouldJsonSerialiseAndDeserialise.
@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
// Given
final ViewElementDefinition elementDef = new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_1, String.class).transientProperty(TestPropertyNames.PROP_2, String.class).properties(TestPropertyNames.COUNT, TestPropertyNames.DATE).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(5)).build()).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.COUNT).execute(new Max()).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsLessThan(10)).build()).transformer(new ElementTransformer.Builder().select(TestPropertyNames.COUNT).execute(new TestTransform()).project(TestPropertyNames.PROP_1).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsEqual("9")).build()).build();
// When
final byte[] json = JSONSerialiser.serialise(elementDef, true);
final ViewElementDefinition deserialisedElementDef = JSONSerialiser.deserialise(json, ViewElementDefinition.class);
assertEquals(Sets.newHashSet(TestPropertyNames.COUNT, TestPropertyNames.DATE), deserialisedElementDef.getProperties());
assertNull(deserialisedElementDef.getExcludeProperties());
final List<TupleAdaptedPredicate<String, ?>> preFilterComponents = deserialisedElementDef.getPreAggregationFilter().getComponents();
assertThat(preFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, preFilterComponents.get(0).getSelection());
assertEquals(new IsMoreThan(5), preFilterComponents.get(0).getPredicate());
final List<TupleAdaptedBinaryOperator<String, ?>> aggComponents = deserialisedElementDef.getAggregator().getComponents();
assertThat(aggComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, aggComponents.get(0).getSelection());
assertEquals(new Max(), aggComponents.get(0).getBinaryOperator());
final List<TupleAdaptedPredicate<String, ?>> postFilterComponents = deserialisedElementDef.getPostAggregationFilter().getComponents();
assertThat(postFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, postFilterComponents.get(0).getSelection());
assertEquals(new IsLessThan(10), postFilterComponents.get(0).getPredicate());
final List<TupleAdaptedFunction<String, ?, ?>> transformComponents = deserialisedElementDef.getTransformer().getComponents();
assertThat(transformComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, transformComponents.get(0).getSelection());
assertEquals(new TestTransform(), transformComponents.get(0).getFunction());
assertArrayEquals(new String[] { TestPropertyNames.PROP_1 }, transformComponents.get(0).getProjection());
final List<TupleAdaptedPredicate<String, ?>> postTransformFilterComponents = deserialisedElementDef.getPostTransformFilter().getComponents();
assertThat(postTransformFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.PROP_1 }, postTransformFilterComponents.get(0).getSelection());
assertEquals(new IsEqual("9"), postTransformFilterComponents.get(0).getPredicate());
}
use of uk.gov.gchq.koryphe.impl.binaryoperator.Max 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.koryphe.impl.binaryoperator.Max 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);
}
use of uk.gov.gchq.koryphe.impl.binaryoperator.Max in project Gaffer by gchq.
the class AccumuloStoreTest method shouldValidateTimestampPropertyHasMaxAggregator.
@Test
public void shouldValidateTimestampPropertyHasMaxAggregator() throws Exception {
// Given
final AccumuloStore store = new MiniAccumuloStore();
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex(TestTypes.ID_STRING).property(TestPropertyNames.TIMESTAMP, TestTypes.TIMESTAMP).build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_EITHER).property(TestPropertyNames.TIMESTAMP, TestTypes.TIMESTAMP_2).build()).type(TestTypes.ID_STRING, String.class).type(TestTypes.DIRECTED_EITHER, new TypeDefinition.Builder().clazz(Boolean.class).build()).type(TestTypes.TIMESTAMP, new TypeDefinition.Builder().clazz(Long.class).aggregateFunction(new Max()).build()).type(TestTypes.TIMESTAMP_2, new TypeDefinition.Builder().clazz(Long.class).aggregateFunction(new Max()).build()).timestampProperty(TestPropertyNames.TIMESTAMP).build();
// When
store.initialise("graphId", schema, PROPERTIES);
// Then - no validation exceptions
}
Aggregations