use of org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector in project hive by apache.
the class TestGenericUDFExtractUnionObjectInspectorConverter method convertUnion.
@Test
public void convertUnion() {
ObjectInspector result = underTest.convert(unionObjectInspector);
assertThat(result, is(structObjectInspector));
assertThat(result.getTypeName(), is(structObjectInspector.getTypeName()));
}
use of org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector in project hive by apache.
the class TestGenericUDFExtractUnionValueConverter method convertStruct.
@Test
public void convertStruct() {
ObjectInspector inspector = ObjectInspectorFactory.getStandardStructObjectInspector(Arrays.asList("foo"), Arrays.<ObjectInspector>asList(unionObjectInspector));
Object value = Arrays.asList(union);
@SuppressWarnings("unchecked") List<Object> result = (List<Object>) underTest.convert(value, inspector);
assertThat(result.size(), is(1));
assertThat(result.get(0), is((Object) Arrays.asList("foo", null)));
}
use of org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector in project hive by apache.
the class TestGenericUDFExtractUnionValueConverter method convertList.
@Test
public void convertList() {
ObjectInspector inspector = ObjectInspectorFactory.getStandardListObjectInspector(unionObjectInspector);
Object value = Arrays.asList(union);
@SuppressWarnings("unchecked") List<Object> result = (List<Object>) underTest.convert(value, inspector);
assertThat(result.size(), is(1));
assertThat(result.get(0), is((Object) Arrays.asList("foo", null)));
}
use of org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector in project hive by apache.
the class TestGenericUDFExtractUnionValueConverter method convertMap.
@Test
public void convertMap() {
ObjectInspector inspector = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, unionObjectInspector);
Object value = Collections.singletonMap("bar", union);
@SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) underTest.convert(value, inspector);
assertThat(result.size(), is(1));
assertThat(result.get("bar"), is((Object) Arrays.asList("foo", null)));
}
use of org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector in project hive by apache.
the class SerdeRandomRowSource method getObjectInspector.
private ObjectInspector getObjectInspector(TypeInfo typeInfo) {
ObjectInspector objectInspector;
switch(typeInfo.getCategory()) {
case PRIMITIVE:
{
final PrimitiveTypeInfo primitiveType = (PrimitiveTypeInfo) typeInfo;
objectInspector = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(primitiveType);
}
break;
case MAP:
{
final MapTypeInfo mapType = (MapTypeInfo) typeInfo;
final MapObjectInspector mapInspector = ObjectInspectorFactory.getStandardMapObjectInspector(getObjectInspector(mapType.getMapKeyTypeInfo()), getObjectInspector(mapType.getMapValueTypeInfo()));
objectInspector = mapInspector;
}
break;
case LIST:
{
final ListTypeInfo listType = (ListTypeInfo) typeInfo;
final ListObjectInspector listInspector = ObjectInspectorFactory.getStandardListObjectInspector(getObjectInspector(listType.getListElementTypeInfo()));
objectInspector = listInspector;
}
break;
case STRUCT:
{
final StructTypeInfo structType = (StructTypeInfo) typeInfo;
final List<TypeInfo> fieldTypes = structType.getAllStructFieldTypeInfos();
final List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>();
for (TypeInfo fieldType : fieldTypes) {
fieldInspectors.add(getObjectInspector(fieldType));
}
final StructObjectInspector structInspector = ObjectInspectorFactory.getStandardStructObjectInspector(structType.getAllStructFieldNames(), fieldInspectors);
objectInspector = structInspector;
}
break;
case UNION:
{
final UnionTypeInfo unionType = (UnionTypeInfo) typeInfo;
final List<TypeInfo> fieldTypes = unionType.getAllUnionObjectTypeInfos();
final List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>();
for (TypeInfo fieldType : fieldTypes) {
fieldInspectors.add(getObjectInspector(fieldType));
}
final UnionObjectInspector unionInspector = ObjectInspectorFactory.getStandardUnionObjectInspector(fieldInspectors);
objectInspector = unionInspector;
}
break;
default:
throw new RuntimeException("Unexpected category " + typeInfo.getCategory());
}
Preconditions.checkState(objectInspector != null);
return objectInspector;
}
Aggregations