Search in sources :

Example 1 with SchemaException

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

the class AccumuloKeyValueReducer method setup.

@Override
protected void setup(final Context context) {
    try {
        schema = Schema.fromJson(context.getConfiguration().get(AddElementsFromHdfsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise schema from JSON", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(context.getConfiguration().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 IllegalArgumentException("Failed to create accumulo element converter from class", 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 2 with SchemaException

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

the class OperationDeclarations method fromPaths.

public static OperationDeclarations fromPaths(final String paths) {
    final OperationDeclarations allDefinitions = new OperationDeclarations.Builder().build();
    try {
        for (final String pathStr : paths.split(",")) {
            final OperationDeclarations definitions;
            final Path path = Paths.get(pathStr);
            if (path.toFile().exists()) {
                definitions = fromJson(Files.readAllBytes(path));
            } else {
                definitions = fromJson(StreamUtil.openStream(OperationDeclarations.class, pathStr));
            }
            if (null != definitions && null != definitions.getOperations()) {
                allDefinitions.getOperations().addAll(definitions.getOperations());
            }
        }
    } catch (final IOException e) {
        throw new SchemaException("Failed to load element definitions from paths: " + paths, e);
    }
    return allDefinitions;
}
Also used : Path(java.nio.file.Path) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) IOException(java.io.IOException)

Example 3 with SchemaException

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

the class ElementInputFormat method createRecordReader.

@Override
public RecordReader<Element, NullWritable> createRecordReader(final InputSplit split, final TaskAttemptContext context) throws IOException, InterruptedException {
    log.setLevel(getLogLevel(context));
    final Configuration conf = context.getConfiguration();
    final String keyPackageClass = conf.get(KEY_PACKAGE);
    final Schema schema = Schema.fromJson(conf.get(SCHEMA).getBytes(CommonConstants.UTF_8));
    final View view = View.fromJson(conf.get(VIEW).getBytes(CommonConstants.UTF_8));
    try {
        return new ElementWithPropertiesRecordReader(keyPackageClass, schema, view);
    } catch (final StoreException | SchemaException | SerialisationException e) {
        throw new IOException("Exception creating RecordReader", e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Configuration(org.apache.hadoop.conf.Configuration) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) IOException(java.io.IOException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 4 with SchemaException

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

the class GraphTest method shouldThrowExceptionWithInvalidSchema.

@Test
public void shouldThrowExceptionWithInvalidSchema() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    // When / Then
    try {
        new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).addSchema(new Schema.Builder().edge("group", new SchemaEdgeDefinition()).entity("group", new SchemaEntityDefinition()).build()).storeProperties(storeProperties).build();
    } catch (final SchemaException e) {
        assertTrue(e.getMessage().contains("Schema is not valid"));
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 5 with SchemaException

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

the class SchemaUtils method buildParquetSchema.

private MessageType buildParquetSchema(final String group) throws SerialisationException {
    SchemaElementDefinition groupGafferSchema;
    final boolean isEntity = gafferSchema.getEntityGroups().contains(group);
    final StringBuilder schemaString = new StringBuilder("message Element {\n");
    Serialiser serialiser = gafferSchema.getVertexSerialiser();
    // Check that the vertex does not get stored as nested data
    if (serialiser instanceof ParquetSerialiser && ((ParquetSerialiser) serialiser).getParquetSchema("test").contains(" group ")) {
        throw new SerialisationException("Can not have a vertex that is serialised as nested data as it can not be indexed");
    }
    if (isEntity) {
        groupGafferSchema = gafferSchema.getEntity(group);
        schemaString.append(convertColumnSerialiserToParquetColumns(serialiser, ParquetStore.VERTEX)).append("\n");
        addGroupColumnToSerialiser(group, ParquetStore.VERTEX, serialiser);
    } else {
        groupGafferSchema = gafferSchema.getEdge(group);
        schemaString.append(convertColumnSerialiserToParquetColumns(serialiser, ParquetStore.SOURCE)).append("\n");
        addGroupColumnToSerialiser(group, ParquetStore.SOURCE, serialiser);
        schemaString.append(convertColumnSerialiserToParquetColumns(serialiser, ParquetStore.DESTINATION)).append("\n");
        addGroupColumnToSerialiser(group, ParquetStore.DESTINATION, serialiser);
        addGroupColumnToSerialiser(group, ParquetStore.DIRECTED, BooleanParquetSerialiser.class.getCanonicalName());
        schemaString.append(convertColumnSerialiserToParquetColumns(getSerialiser(BooleanParquetSerialiser.class.getCanonicalName()), ParquetStore.DIRECTED)).append("\n");
    }
    Map<String, String> propertyMap = groupGafferSchema.getPropertyMap();
    for (final Map.Entry<String, String> entry : propertyMap.entrySet()) {
        if (entry.getKey().contains("_") || entry.getKey().contains(".")) {
            throw new SchemaException("The ParquetStore does not support properties which contain the characters '_' or '.'");
        }
        final TypeDefinition type = gafferSchema.getType(entry.getValue());
        addGroupColumnToSerialiser(group, entry.getKey(), type.getSerialiserClass());
        schemaString.append(convertColumnSerialiserToParquetColumns(getSerialiser(type.getSerialiserClass()), entry.getKey())).append("\n");
    }
    schemaString.append("}");
    String parquetSchemaString = schemaString.toString();
    final MessageType parquetSchema = MessageTypeParser.parseMessageType(parquetSchemaString);
    LOGGER.debug("Generated Parquet schema: " + parquetSchemaString);
    return parquetSchema;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) BooleanParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.BooleanParquetSerialiser) ParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.ParquetSerialiser) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) BooleanParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.BooleanParquetSerialiser) ParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.ParquetSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) BooleanParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.BooleanParquetSerialiser) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) MessageType(org.apache.parquet.schema.MessageType)

Aggregations

SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)24 Schema (uk.gov.gchq.gaffer.store.schema.Schema)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Test (org.junit.jupiter.api.Test)8 Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)6 AggregationException (uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException)5 AccumuloElementConverter (uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)4 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)4 GetSchema (uk.gov.gchq.gaffer.store.operation.GetSchema)4 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)4 List (java.util.List)3 Graph (uk.gov.gchq.gaffer.graph.Graph)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2