use of org.apache.avro.SchemaParseException in project nifi by apache.
the class RestSchemaRegistryClient method createRecordSchema.
private RecordSchema createRecordSchema(final JsonNode schemaNode) throws SchemaNotFoundException {
final String subject = schemaNode.get(SUBJECT_FIELD_NAME).asText();
final int version = schemaNode.get(VERSION_FIELD_NAME).asInt();
final int id = schemaNode.get(ID_FIELD_NAME).asInt();
final String schemaText = schemaNode.get(SCHEMA_TEXT_FIELD_NAME).asText();
try {
final Schema avroSchema = new Schema.Parser().parse(schemaText);
final SchemaIdentifier schemaId = SchemaIdentifier.builder().name(subject).id(Long.valueOf(id)).version(version).build();
final RecordSchema recordSchema = AvroTypeUtil.createSchema(avroSchema, schemaText, schemaId);
return recordSchema;
} catch (final SchemaParseException spe) {
throw new SchemaNotFoundException("Obtained Schema with id " + id + " and name " + subject + " from Confluent Schema Registry but the Schema Text that was returned is not a valid Avro Schema");
}
}
use of org.apache.avro.SchemaParseException in project flink by apache.
the class AvroSchemaConverter method convertToDataType.
/**
* Converts an Avro schema string into a nested row structure with deterministic field order and
* data types that are compatible with Flink's Table & SQL API.
*
* @param avroSchemaString Avro schema definition string
* @return data type matching the schema
*/
public static DataType convertToDataType(String avroSchemaString) {
Preconditions.checkNotNull(avroSchemaString, "Avro schema must not be null.");
final Schema schema;
try {
schema = new Schema.Parser().parse(avroSchemaString);
} catch (SchemaParseException e) {
throw new IllegalArgumentException("Could not parse Avro schema string.", e);
}
return convertToDataType(schema);
}
use of org.apache.avro.SchemaParseException in project flink by apache.
the class AvroSchemaConverter method convertToTypeInfo.
/**
* Converts an Avro schema string into a nested row structure with deterministic field order and
* data types that are compatible with Flink's Table & SQL API.
*
* @param avroSchemaString Avro schema definition string
* @return type information matching the schema
*/
@SuppressWarnings("unchecked")
public static <T> TypeInformation<T> convertToTypeInfo(String avroSchemaString) {
Preconditions.checkNotNull(avroSchemaString, "Avro schema must not be null.");
final Schema schema;
try {
schema = new Schema.Parser().parse(avroSchemaString);
} catch (SchemaParseException e) {
throw new IllegalArgumentException("Could not parse Avro schema string.", e);
}
return (TypeInformation<T>) convertToTypeInfo(schema);
}
use of org.apache.avro.SchemaParseException in project gora by apache.
the class AbstractGoraMojo method compile.
protected void compile() throws IOException {
File sourceDirectory = getSourcesDirectory();
File outputDirectory = getOutputDirectory();
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
Scanner fileScanner = context.newScanner(sourceDirectory, true);
fileScanner.setIncludes(includes);
fileScanner.setExcludes(excludes);
fileScanner.scan();
File basedir = fileScanner.getBasedir();
List<File> changedFiles = new ArrayList<File>();
for (String fileName : fileScanner.getIncludedFiles()) {
File file = new File(basedir, fileName);
changedFiles.add(file);
context.removeMessages(file);
}
if (!changedFiles.isEmpty()) {
try {
File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
GoraCompiler.compileSchema(schemaFile, outputDirectory);
} catch (SchemaParseException e) {
if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
attachErrorMessage((JsonParseException) e.getCause());
} else {
throw e;
}
}
}
context.refresh(outputDirectory);
}
use of org.apache.avro.SchemaParseException in project cdap by caskdata.
the class AvroRecordFormat method validateSchema.
@Override
protected void validateSchema(Schema desiredSchema) throws UnsupportedTypeException {
try {
// rather than check for all inconsistencies, just try to read the schema string as an Avro schema.
avroFormatSchema = new org.apache.avro.Schema.Parser().parse(desiredSchema.toString());
formatSchema = desiredSchema;
} catch (SchemaParseException e) {
throw new UnsupportedTypeException("Schema is not a valid avro schema.", e);
} catch (Exception e) {
throw new UnsupportedTypeException("Exception parsing schema as an avro schema.", e);
}
}
Aggregations