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