use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.
the class TestAvroSerdeUtils method noneOptionWorksForSpecifyingSchemas.
@Test
public void noneOptionWorksForSpecifyingSchemas() throws IOException, AvroSerdeException {
Configuration conf = new Configuration();
Properties props = new Properties();
// Combo 1: Both set to none
props.put(AvroTableProperties.SCHEMA_URL.getPropName(), SCHEMA_NONE);
props.put(AvroTableProperties.SCHEMA_LITERAL.getPropName(), SCHEMA_NONE);
try {
determineSchemaOrThrowException(conf, props);
fail("Should have thrown exception with none set for both url and literal");
} catch (AvroSerdeException he) {
assertEquals(EXCEPTION_MESSAGE, he.getMessage());
}
// Combo 2: Literal set, url set to none
props.put(AvroTableProperties.SCHEMA_LITERAL.getPropName(), TestAvroObjectInspectorGenerator.RECORD_SCHEMA);
Schema s;
try {
s = determineSchemaOrThrowException(conf, props);
assertNotNull(s);
assertEquals(AvroSerdeUtils.getSchemaFor(TestAvroObjectInspectorGenerator.RECORD_SCHEMA), s);
} catch (AvroSerdeException he) {
fail("Should have parsed schema literal, not thrown exception.");
}
// Combo 3: url set, literal set to none
props.put(AvroTableProperties.SCHEMA_LITERAL.getPropName(), SCHEMA_NONE);
props.put(AvroTableProperties.SCHEMA_URL.getPropName(), "not:///a.real.url");
try {
determineSchemaOrThrowException(conf, props);
fail("Should have tried to open that bogus URL");
} catch (AvroSerdeException e) {
assertEquals("Unable to read schema from given path: not:///a.real.url", e.getMessage());
}
}
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);
}
use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.
the class SchemaToTypeInfo method generateUnionTypeInfo.
private static TypeInfo generateUnionTypeInfo(Schema schema, Set<Schema> seenSchemas) throws AvroSerdeException {
assert schema.getType().equals(Schema.Type.UNION);
List<Schema> types = schema.getTypes();
List<TypeInfo> typeInfos = new ArrayList<TypeInfo>(types.size());
for (Schema type : types) {
typeInfos.add(generateTypeInfo(type, seenSchemas));
}
return TypeInfoFactory.getUnionTypeInfo(typeInfos);
}
use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.
the class AvroObjectInspectorGenerator method createObjectInspectorWorker.
private ObjectInspector createObjectInspectorWorker(TypeInfo ti) throws SerDeException {
// at deserialization and the object inspector will never see the actual union.
if (!supportedCategories(ti)) {
throw new AvroSerdeException("Don't yet support this type: " + ti);
}
ObjectInspector result;
switch(ti.getCategory()) {
case PRIMITIVE:
PrimitiveTypeInfo pti = (PrimitiveTypeInfo) ti;
result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti);
break;
case STRUCT:
StructTypeInfo sti = (StructTypeInfo) ti;
ArrayList<ObjectInspector> ois = new ArrayList<ObjectInspector>(sti.getAllStructFieldTypeInfos().size());
for (TypeInfo typeInfo : sti.getAllStructFieldTypeInfos()) {
ois.add(createObjectInspectorWorker(typeInfo));
}
result = ObjectInspectorFactory.getStandardStructObjectInspector(sti.getAllStructFieldNames(), ois);
break;
case MAP:
MapTypeInfo mti = (MapTypeInfo) ti;
result = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveObjectInspector.PrimitiveCategory.STRING), createObjectInspectorWorker(mti.getMapValueTypeInfo()));
break;
case LIST:
ListTypeInfo ati = (ListTypeInfo) ti;
result = ObjectInspectorFactory.getStandardListObjectInspector(createObjectInspectorWorker(ati.getListElementTypeInfo()));
break;
case UNION:
UnionTypeInfo uti = (UnionTypeInfo) ti;
List<TypeInfo> allUnionObjectTypeInfos = uti.getAllUnionObjectTypeInfos();
List<ObjectInspector> unionObjectInspectors = new ArrayList<ObjectInspector>(allUnionObjectTypeInfos.size());
for (TypeInfo typeInfo : allUnionObjectTypeInfos) {
unionObjectInspectors.add(createObjectInspectorWorker(typeInfo));
}
result = ObjectInspectorFactory.getStandardUnionObjectInspector(unionObjectInspectors);
break;
default:
throw new AvroSerdeException("No Hive categories matched: " + ti);
}
return result;
}
use of org.apache.hadoop.hive.serde2.avro.AvroSerdeException in project hive by apache.
the class AvroSerializer method serializeList.
private Object serializeList(ListTypeInfo typeInfo, ListObjectInspector fieldOI, Object structFieldData, Schema schema) throws AvroSerdeException {
List<?> list = fieldOI.getList(structFieldData);
List<Object> deserialized = new GenericData.Array<Object>(list.size(), schema);
TypeInfo listElementTypeInfo = typeInfo.getListElementTypeInfo();
ObjectInspector listElementObjectInspector = fieldOI.getListElementObjectInspector();
Schema elementType = schema.getElementType();
for (int i = 0; i < list.size(); i++) {
deserialized.add(i, serialize(listElementTypeInfo, listElementObjectInspector, list.get(i), elementType));
}
return deserialized;
}
Aggregations