use of org.apache.avro.Schema.Parser in project nifi by apache.
the class ValidateRecord method getValidationSchema.
protected RecordSchema getValidationSchema(final ProcessContext context, final FlowFile flowFile, final RecordReader reader) throws MalformedRecordException, IOException, SchemaNotFoundException {
final String schemaAccessStrategy = context.getProperty(SCHEMA_ACCESS_STRATEGY).getValue();
if (schemaAccessStrategy.equals(READER_SCHEMA.getValue())) {
return reader.getSchema();
} else if (schemaAccessStrategy.equals(SCHEMA_NAME_PROPERTY.getValue())) {
final SchemaRegistry schemaRegistry = context.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class);
final String schemaName = context.getProperty(SCHEMA_NAME).evaluateAttributeExpressions(flowFile).getValue();
final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name(schemaName).build();
return schemaRegistry.retrieveSchema(schemaIdentifier);
} else if (schemaAccessStrategy.equals(SCHEMA_TEXT_PROPERTY.getValue())) {
final String schemaText = context.getProperty(SCHEMA_TEXT).evaluateAttributeExpressions(flowFile).getValue();
final Parser parser = new Schema.Parser();
final Schema avroSchema = parser.parse(schemaText);
return AvroTypeUtil.createSchema(avroSchema);
} else {
throw new ProcessException("Invalid Schema Access Strategy: " + schemaAccessStrategy);
}
}
use of org.apache.avro.Schema.Parser in project Gaffer by gchq.
the class AvroJobInitialiser method initialiseInput.
private void initialiseInput(final Job job, final MapReduce operation) throws IOException {
if (null == avroSchemaFilePath) {
throw new IllegalArgumentException("Avro schema file path has not been set");
}
final Schema schema = new Parser().parse(new File(avroSchemaFilePath));
AvroJob.setInputKeySchema(job, schema);
job.setInputFormatClass(AvroKeyInputFormat.class);
for (final Map.Entry<String, String> entry : operation.getInputMapperPairs().entrySet()) {
if (entry.getValue().contains(job.getConfiguration().get(MAPPER_GENERATOR))) {
AvroKeyInputFormat.addInputPath(job, new Path(entry.getKey()));
}
}
}
use of org.apache.avro.Schema.Parser in project Gaffer by gchq.
the class AvroJobInitialiser method initialiseInput.
private void initialiseInput(final Job job, final MapReduceOperation operation) throws IOException {
if (null == avroSchemaFilePath) {
throw new IllegalArgumentException("Avro schema file path has not been set");
}
final Schema schema = new Parser().parse(new File(avroSchemaFilePath));
AvroJob.setInputKeySchema(job, schema);
job.setInputFormatClass(AvroKeyInputFormat.class);
List<String> paths = operation.getInputPaths();
for (final String path : paths) {
AvroKeyInputFormat.addInputPath(job, new Path(path));
}
}
use of org.apache.avro.Schema.Parser in project flink by apache.
the class GlueSchemaRegistryInputStreamDeserializer method getSchemaAndDeserializedStream.
/**
* Get schema and remove extra Schema Registry information within input stream.
*
* @param in input stream
* @return schema of object within input stream
* @throws IOException Exception during decompression
*/
public Schema getSchemaAndDeserializedStream(InputStream in) throws IOException {
byte[] inputBytes = new byte[in.available()];
in.read(inputBytes);
in.reset();
MutableByteArrayInputStream mutableByteArrayInputStream = (MutableByteArrayInputStream) in;
String schemaDefinition = glueSchemaRegistryDeserializationFacade.getSchemaDefinition(inputBytes);
byte[] deserializedBytes = glueSchemaRegistryDeserializationFacade.getActualData(inputBytes);
mutableByteArrayInputStream.setBuffer(deserializedBytes);
Schema schema;
try {
Parser schemaParser = new Schema.Parser();
schema = schemaParser.parse(schemaDefinition);
} catch (SchemaParseException e) {
String message = "Error occurred while parsing schema, see inner exception for details.";
throw new AWSSchemaRegistryException(message, e);
}
return schema;
}
Aggregations