Search in sources :

Example 1 with AggregationException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException in project Gaffer by gchq.

the class CoreKeyGroupByAggregatorIterator method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!super.validateOptions(options)) {
        return false;
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    return true;
}
Also used : AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with AggregationException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException in project Gaffer by gchq.

the class AggregatorIterator method reduce.

@Override
public Value reduce(final Key key, final Iterator<Value> iter) {
    // Get first Value. If this is the only Value then return it straight
    // away;
    Value value = iter.next();
    if (!iter.hasNext()) {
        return value;
    }
    final String group;
    try {
        group = new String(key.getColumnFamilyData().getBackingArray(), CommonConstants.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        throw new AggregationException("Failed to recreate a graph element from a key and value", e);
    }
    Properties properties;
    final ElementAggregator aggregator;
    try {
        properties = elementConverter.getPropertiesFromValue(group, value);
    } catch (final AccumuloElementConversionException e) {
        throw new AggregationException("Failed to recreate a graph element from a key and value", e);
    }
    aggregator = schema.getElement(group).getAggregator();
    aggregator.aggregate(properties);
    while (iter.hasNext()) {
        value = iter.next();
        try {
            properties = elementConverter.getPropertiesFromValue(group, value);
        } catch (final AccumuloElementConversionException e) {
            throw new AggregationException("Failed to recreate a graph element from a key and value", e);
        }
        aggregator.aggregate(properties);
    }
    properties = new Properties();
    aggregator.state(properties);
    try {
        return elementConverter.getValueFromProperties(group, properties);
    } catch (final AccumuloElementConversionException e) {
        throw new AggregationException("Failed to create an accumulo value from an elements properties", e);
    }
}
Also used : AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Value(org.apache.accumulo.core.data.Value) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(uk.gov.gchq.gaffer.data.element.Properties) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 3 with AggregationException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException in project Gaffer by gchq.

the class RowIDAggregator method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
    }
    if (!options.containsKey(AccumuloStoreConstants.COLUMN_FAMILY)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.COLUMN_FAMILY);
    }
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    group = options.get(AccumuloStoreConstants.COLUMN_FAMILY);
    aggregator = schema.getElement(group).getAggregator();
    return true;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with AggregationException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException in project Gaffer by gchq.

the class AggregatorIterator method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!super.validateOptions(options)) {
        return false;
    }
    if (!options.containsKey(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    }
    if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
    }
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema from json", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    return true;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AggregationException (uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)2 Value (org.apache.accumulo.core.data.Value)1 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)1 Properties (uk.gov.gchq.gaffer.data.element.Properties)1 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1