Search in sources :

Example 1 with StringConcat

use of uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat 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 StringConcat

use of uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat in project Gaffer by gchq.

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithViewAggregator.

@Test
public void shouldReturnQueryAggregatorWithViewAggregator() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property3", "property4").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    final ElementAggregator viewAggregator = new ElementAggregator.Builder().select("property1").execute(new StringConcat()).build();
    // When
    final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator);
    // Then
    int i = 0;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat);
    assertArrayEquals(new String[] { "property1" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "property4" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property2" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertEquals(i, aggregator.getComponents().size());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is not cached
    assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator));
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 3 with StringConcat

use of uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat in project Gaffer by gchq.

the class SchemaElementDefinitionTest method shouldReturnQueryAggregatorWithViewAggregatorAndMultipleAgg.

@Test
public void shouldReturnQueryAggregatorWithViewAggregatorAndMultipleAgg() {
    // Given
    final T elementDef = createBuilder().property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).property("property3", PROPERTY_STRING_TYPE).property("property4", PROPERTY_STRING_TYPE).property("property5", PROPERTY_STRING_TYPE).property("visibility", PROPERTY_STRING_TYPE).property("timestamp", PROPERTY_STRING_TYPE).groupBy("property1", "property2").aggregator(new ElementAggregator.Builder().select("property1", "property2").execute(new ExampleTuple2BinaryOperator()).select("property3", "property4").execute(new ExampleTuple2BinaryOperator()).build()).build();
    setupSchema(elementDef);
    final ElementAggregator viewAggregator = new ElementAggregator.Builder().select("property1").execute(new StringConcat()).build();
    // When
    final ElementAggregator aggregator = elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator);
    // Then
    int i = 0;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof StringConcat);
    assertArrayEquals(new String[] { "property1" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property1", "property2" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleTuple2BinaryOperator);
    assertArrayEquals(new String[] { "property3", "property4" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "property5" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "visibility" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertTrue(aggregator.getComponents().get(i).getBinaryOperator() instanceof ExampleAggregateFunction);
    assertArrayEquals(new String[] { "timestamp" }, aggregator.getComponents().get(i).getSelection());
    i++;
    assertEquals(i, aggregator.getComponents().size());
    // Check the aggregator is locked.
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> aggregator.getComponents().add(null)).isNotNull();
    // check the aggregator is not cached
    assertNotSame(aggregator, elementDef.getQueryAggregator(Sets.newHashSet(), viewAggregator));
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ExampleTuple2BinaryOperator(uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 4 with StringConcat

use of uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat in project Gaffer by gchq.

the class TableUtilsTest method shouldFailTableValidationWhenMissingAggregatorIterator.

@Test
public void shouldFailTableValidationWhenMissingAggregatorIterator() throws Exception {
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).validateFunctions(new Exists()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    store.initialise(GRAPH_ID, schema, PROPERTIES);
    final Runnable invalidateTable = () -> {
        try {
            AddUpdateTableIterator.removeIterator(store, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME);
        } catch (final StoreException e) {
            throw new RuntimeException(e);
        }
    };
    shouldFailTableValidationWhenTableInvalid(store, invalidateTable);
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) AccumuloRuntimeException(uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) Schema(uk.gov.gchq.gaffer.store.schema.Schema) MiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) StoreException(uk.gov.gchq.gaffer.store.StoreException) Test(org.junit.jupiter.api.Test)

Example 5 with StringConcat

use of uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat in project Gaffer by gchq.

the class TableUtilsTest method shouldCreateTableAndValidateIt.

@Test
public void shouldCreateTableAndValidateIt() throws Exception {
    // Given
    final SingleUseMiniHBaseStore store = new SingleUseMiniHBaseStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    final HBaseProperties props = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    store.initialise(GRAPH_ID, schema, props);
    // When
    TableUtils.createTable(store);
    TableUtils.ensureTableExists(store);
// Then - no exceptions
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniHBaseStore(uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)16 Test (org.junit.jupiter.api.Test)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)6 StoreException (uk.gov.gchq.gaffer.store.StoreException)4 AccumuloStore (uk.gov.gchq.gaffer.accumulostore.AccumuloStore)3 MiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore)3 SingleUseMiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore)3 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)3 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)3 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)3 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 AccumuloRuntimeException (uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)2 ExampleTuple2BinaryOperator (uk.gov.gchq.gaffer.function.ExampleTuple2BinaryOperator)2 HBaseProperties (uk.gov.gchq.gaffer.hbasestore.HBaseProperties)2 SingleUseMiniHBaseStore (uk.gov.gchq.gaffer.hbasestore.SingleUseMiniHBaseStore)2 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)2