Search in sources :

Example 1 with StringConcat

use of uk.gov.gchq.gaffer.function.aggregate.StringConcat in project Gaffer by gchq.

the class GraphTest method shouldThrowExceptionIfSchemaIsInvalid.

@Test
public void shouldThrowExceptionIfSchemaIsInvalid() throws OperationException {
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(StoreImpl.class.getName());
    try {
        new Graph.Builder().addSchema(new Schema.Builder().type("intnoagg", new TypeDefinition.Builder().clazz(Integer.class).build()).type("int", new TypeDefinition.Builder().clazz(Integer.class).aggregateFunction(new Sum()).build()).type("string", new TypeDefinition.Builder().clazz(String.class).aggregateFunction(new StringConcat()).build()).type("boolean", Boolean.class).edge("EDGE", new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("boolean").property("p", "intnoagg").build()).entity("ENTITY", new SchemaEntityDefinition.Builder().vertex("string").property("p2", "int").build()).build()).storeProperties(storeProperties).build();
        fail("exception expected");
    } catch (final SchemaException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) StringConcat(uk.gov.gchq.gaffer.function.aggregate.StringConcat) Sum(uk.gov.gchq.gaffer.function.aggregate.Sum) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.Test)

Example 2 with StringConcat

use of uk.gov.gchq.gaffer.function.aggregate.StringConcat in project Gaffer by gchq.

the class TableUtilsTest method shouldCreateTableWithAllRequiredIterators.

@Test
public void shouldCreateTableWithAllRequiredIterators() throws Exception {
    // Given
    final MockAccumuloStore store = new MockAccumuloStore();
    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 AccumuloProperties props = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    props.setTable(TABLE_NAME);
    store.initialise(schema, props);
    // When
    TableUtils.createTable(store);
    // Then
    final Map<String, EnumSet<IteratorScope>> itrs = store.getConnection().tableOperations().listIterators(TABLE_NAME);
    assertEquals(2, itrs.size());
    final EnumSet<IteratorScope> validator = itrs.get(AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME);
    assertEquals(EnumSet.allOf(IteratorScope.class), validator);
    final IteratorSetting validatorSetting = store.getConnection().tableOperations().getIteratorSetting(TABLE_NAME, AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME, IteratorScope.majc);
    assertEquals(AccumuloStoreConstants.VALIDATOR_ITERATOR_PRIORITY, validatorSetting.getPriority());
    assertEquals(ValidatorFilter.class.getName(), validatorSetting.getIteratorClass());
    final Map<String, String> validatorOptions = validatorSetting.getOptions();
    assertNotNull(Schema.fromJson(validatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
    assertEquals(ByteEntityAccumuloElementConverter.class.getName(), validatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
    final EnumSet<IteratorScope> aggregator = itrs.get(AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME);
    assertEquals(EnumSet.allOf(IteratorScope.class), aggregator);
    final IteratorSetting aggregatorSetting = store.getConnection().tableOperations().getIteratorSetting(TABLE_NAME, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME, IteratorScope.majc);
    assertEquals(AccumuloStoreConstants.AGGREGATOR_ITERATOR_PRIORITY, aggregatorSetting.getPriority());
    assertEquals(AggregatorIterator.class.getName(), aggregatorSetting.getIteratorClass());
    final Map<String, String> aggregatorOptions = aggregatorSetting.getOptions();
    assertNotNull(Schema.fromJson(aggregatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
    assertEquals(ByteEntityAccumuloElementConverter.class.getName(), aggregatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
    final Map<String, String> tableProps = new HashMap<>();
    for (final Map.Entry<String, String> entry : store.getConnection().tableOperations().getProperties(TABLE_NAME)) {
        tableProps.put(entry.getKey(), entry.getValue());
    }
    assertEquals(0, Integer.parseInt(tableProps.get(Property.TABLE_FILE_REPLICATION.getKey())));
}
Also used : StringConcat(uk.gov.gchq.gaffer.function.aggregate.StringConcat) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) EnumSet(java.util.EnumSet) AggregatorIterator(uk.gov.gchq.gaffer.accumulostore.key.impl.AggregatorIterator) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) ValidatorFilter(uk.gov.gchq.gaffer.accumulostore.key.impl.ValidatorFilter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 StringConcat (uk.gov.gchq.gaffer.function.aggregate.StringConcat)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)1 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)1 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)1 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)1 ByteEntityAccumuloElementConverter (uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter)1 AggregatorIterator (uk.gov.gchq.gaffer.accumulostore.key.impl.AggregatorIterator)1 ValidatorFilter (uk.gov.gchq.gaffer.accumulostore.key.impl.ValidatorFilter)1 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)1 Sum (uk.gov.gchq.gaffer.function.aggregate.Sum)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)1