use of org.apache.avro.SchemaParseException 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;
}
use of org.apache.avro.SchemaParseException in project incubator-gobblin by apache.
the class HiveMetaStoreUtils method getDeserializer.
/**
* Returns a Deserializer from HiveRegistrationUnit if present and successfully initialized. Else returns null.
*/
private static Deserializer getDeserializer(HiveRegistrationUnit unit) {
Optional<String> serdeClass = unit.getSerDeType();
if (!serdeClass.isPresent()) {
return null;
}
String serde = serdeClass.get();
HiveConf hiveConf;
Deserializer deserializer;
try {
hiveConf = SharedResourcesBrokerFactory.getImplicitBroker().getSharedResource(new HiveConfFactory<>(), SharedHiveConfKey.INSTANCE);
deserializer = ReflectionUtils.newInstance(hiveConf.getClassByName(serde).asSubclass(Deserializer.class), hiveConf);
} catch (ClassNotFoundException e) {
LOG.warn("Serde class " + serde + " not found!", e);
return null;
} catch (NotConfiguredException nce) {
LOG.error("Implicit broker is not configured properly", nce);
return null;
}
Properties props = new Properties();
props.putAll(unit.getProps().getProperties());
props.putAll(unit.getStorageProps().getProperties());
props.putAll(unit.getSerDeProps().getProperties());
try {
SerDeUtils.initializeSerDe(deserializer, hiveConf, props, null);
// handling in AvroSerDe added in HIVE-7868.
if (deserializer instanceof AvroSerDe) {
try {
inVokeDetermineSchemaOrThrowExceptionMethod(props, new Configuration());
} catch (SchemaParseException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
LOG.warn("Failed to initialize AvroSerDe.");
throw new SerDeException(e);
}
}
} catch (SerDeException e) {
LOG.warn("Failed to initialize serde " + serde + " with properties " + props + " for table " + unit.getDbName() + "." + unit.getTableName());
return null;
}
return deserializer;
}
Aggregations