Search in sources :

Example 11 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException 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 12 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.

the class SampleDataForSplitPointsMapper method setup.

protected void setup(final Context context) {
    super.setup(context);
    proportionToSample = context.getConfiguration().getFloat(SampleDataForSplitPointsJobFactory.PROPORTION_TO_SAMPLE, 0.001f);
    final Schema schema;
    try {
        schema = Schema.fromJson(context.getConfiguration().get(SampleDataForSplitPointsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise Store Schema from JSON", e);
    }
    final String converterClass = context.getConfiguration().get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    try {
        final Class<?> elementConverterClass = Class.forName(converterClass);
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new IllegalArgumentException("Element converter could not be created: " + converterClass, e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with SchemaException

use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException 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

SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Test (org.junit.Test)4 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 AggregationException (uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)2 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 ElementFilterException (uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 StringConcat (uk.gov.gchq.gaffer.function.aggregate.StringConcat)1 Sum (uk.gov.gchq.gaffer.function.aggregate.Sum)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1