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