Search in sources :

Example 1 with UnresolvedUnionException

use of org.apache.avro.UnresolvedUnionException in project hive by apache.

the class AvroDeserializer method deserializeSingleItemNullableUnion.

private Object deserializeSingleItemNullableUnion(Object datum, Schema fileSchema, Schema recordSchema) throws AvroSerdeException {
    // Determine index of value
    int tag = GenericData.get().resolveUnion(recordSchema, datum);
    Schema schema = recordSchema.getTypes().get(tag);
    if (schema.getType().equals(Type.NULL)) {
        return null;
    }
    Schema currentFileSchema = null;
    if (fileSchema != null) {
        if (fileSchema.getType() == Type.UNION) {
            // we need to get the correct tag
            try {
                tag = GenericData.get().resolveUnion(fileSchema, datum);
                currentFileSchema = fileSchema.getTypes().get(tag);
            } catch (UnresolvedUnionException e) {
                if (LOG.isDebugEnabled()) {
                    String datumClazz = null;
                    if (datum != null) {
                        datumClazz = datum.getClass().getName();
                    }
                    String msg = "File schema union could not resolve union. fileSchema = " + fileSchema + ", recordSchema = " + recordSchema + ", datum class = " + datumClazz + ": " + e;
                    LOG.debug(msg, e);
                }
                // This occurs when the datum type is different between
                // the file and record schema. For example if datum is long
                // and the field in the file schema is int. See HIVE-9462.
                // in this case we will re-use the record schema as the file
                // schema, Ultimately we need to clean this code up and will
                // do as a follow-on to HIVE-9462.
                currentFileSchema = schema;
            }
        } else {
            currentFileSchema = fileSchema;
        }
    }
    return worker(datum, currentFileSchema, schema, SchemaToTypeInfo.generateTypeInfo(schema, null));
}
Also used : Schema(org.apache.avro.Schema) UnresolvedUnionException(org.apache.avro.UnresolvedUnionException)

Aggregations

Schema (org.apache.avro.Schema)1 UnresolvedUnionException (org.apache.avro.UnresolvedUnionException)1