Search in sources :

Example 1 with AvroSerdeException

use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.

the class AvroDeserializer method workerBase.

// The actual deserialization may involve nested records, which require recursion.
private List<Object> workerBase(List<Object> objectRow, Schema fileSchema, List<String> columnNames, List<TypeInfo> columnTypes, GenericRecord record) throws AvroSerdeException {
    for (int i = 0; i < columnNames.size(); i++) {
        TypeInfo columnType = columnTypes.get(i);
        String columnName = columnNames.get(i);
        Object datum = record.get(columnName);
        Schema datumSchema = record.getSchema().getField(columnName).schema();
        Schema.Field field = AvroSerdeUtils.isNullableType(fileSchema) ? AvroSerdeUtils.getOtherTypeFromNullableType(fileSchema).getField(columnName) : fileSchema.getField(columnName);
        objectRow.add(worker(datum, field == null ? null : field.schema(), datumSchema, columnType));
    }
    return objectRow;
}
Also used : Schema(org.apache.avro.Schema) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)

Example 2 with AvroSerdeException

use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.

the class SchemaToTypeInfo method generateMapTypeInfo.

/**
   * Generate a TypeInfo for an Avro Map.  This is made slightly simpler in that
   * Avro only allows maps with strings for keys.
   */
private static TypeInfo generateMapTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException {
    assert schema.getType().equals(Schema.Type.MAP);
    Schema valueType = schema.getValueType();
    TypeInfo ti = generateTypeInfo(valueType, seenSchemas);
    return TypeInfoFactory.getMapTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("string"), ti);
}
Also used : Schema(org.apache.avro.Schema) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 3 with AvroSerdeException

use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.

the class SchemaToTypeInfo method generateArrayTypeInfo.

private static TypeInfo generateArrayTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException {
    assert schema.getType().equals(Schema.Type.ARRAY);
    Schema itemsType = schema.getElementType();
    TypeInfo itemsTypeInfo = generateTypeInfo(itemsType, seenSchemas);
    return TypeInfoFactory.getListTypeInfo(itemsTypeInfo);
}
Also used : Schema(org.apache.avro.Schema) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 4 with AvroSerdeException

use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.

the class TestAvroSerdeUtils method determineSchemaThrowsExceptionIfNoSchema.

@Test(expected = AvroSerdeException.class)
public void determineSchemaThrowsExceptionIfNoSchema() throws IOException, AvroSerdeException {
    Configuration conf = new Configuration();
    Properties prop = new Properties();
    AvroSerdeUtils.determineSchemaOrThrowException(conf, prop);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Properties(java.util.Properties) AvroTableProperties(org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.AvroTableProperties) Test(org.junit.Test)

Example 5 with AvroSerdeException

use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.

the class TestAvroSerdeUtils method detemineSchemaTriesToOpenUrl.

@Test
public void detemineSchemaTriesToOpenUrl() throws AvroSerdeException, IOException {
    Configuration conf = new Configuration();
    Properties props = new Properties();
    props.put(AvroTableProperties.SCHEMA_URL.getPropName(), "not:///a.real.url");
    try {
        AvroSerdeUtils.determineSchemaOrThrowException(conf, props);
        fail("Should have tried to open that URL");
    } catch (AvroSerdeException e) {
        assertEquals("Unable to read schema from given path: not:///a.real.url", e.getMessage());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Properties(java.util.Properties) AvroTableProperties(org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.AvroTableProperties) Test(org.junit.Test)

Aggregations

TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)11 Schema (org.apache.avro.Schema)10 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)7 ListTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo)7 MapTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)7 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)7 UnionTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)7 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)5 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)4 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)4 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)4 UnionObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector)4 DateObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector)4 TimestampObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 Configuration (org.apache.hadoop.conf.Configuration)3 AvroTableProperties (org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils.AvroTableProperties)3 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)3