Search in sources :

Example 1 with Max

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.");
            }
        }
    }
}
Also used : Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 2 with Max

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());
}
Also used : TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) TupleAdaptedFunction(uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 3 with Max

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);
}
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 4 with Max

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);
}
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)

Example 5 with Max

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
}
Also used : Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

Max (uk.gov.gchq.koryphe.impl.binaryoperator.Max)6 Test (org.junit.jupiter.api.Test)5 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)2 Aggregate (uk.gov.gchq.gaffer.operation.impl.function.Aggregate)2 AggregatePair (uk.gov.gchq.gaffer.operation.util.AggregatePair)2 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)2 Sum (uk.gov.gchq.koryphe.impl.binaryoperator.Sum)2 ChainedIterable (uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)1 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)1 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)1 Min (uk.gov.gchq.koryphe.impl.binaryoperator.Min)1 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)1 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)1