use of org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo in project hive by apache.
the class VectorRandomRowSource method getObjectInspector.
private ObjectInspector getObjectInspector(TypeInfo typeInfo) {
final 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;
}
use of org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo in project incubator-gobblin by apache.
the class HiveAvroORCQueryGenerator method escapeHiveType.
/**
* Escape the Hive nested field names.
* @param type Primitive or nested Hive type.
* @return Escaped Hive nested field.
*/
public static String escapeHiveType(String type) {
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(type);
// Primitve
if (ObjectInspector.Category.PRIMITIVE.equals(typeInfo.getCategory())) {
return type;
} else // List
if (ObjectInspector.Category.LIST.equals(typeInfo.getCategory())) {
ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
return org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "<" + escapeHiveType(listTypeInfo.getListElementTypeInfo().getTypeName()) + ">";
} else // Map
if (ObjectInspector.Category.MAP.equals(typeInfo.getCategory())) {
MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
return org.apache.hadoop.hive.serde.serdeConstants.MAP_TYPE_NAME + "<" + escapeHiveType(mapTypeInfo.getMapKeyTypeInfo().getTypeName()) + "," + escapeHiveType(mapTypeInfo.getMapValueTypeInfo().getTypeName()) + ">";
} else // Struct
if (ObjectInspector.Category.STRUCT.equals(typeInfo.getCategory())) {
StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
List<String> allStructFieldNames = structTypeInfo.getAllStructFieldNames();
List<TypeInfo> allStructFieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
StringBuilder sb = new StringBuilder();
sb.append(serdeConstants.STRUCT_TYPE_NAME + "<");
for (int i = 0; i < allStructFieldNames.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append("`");
sb.append(allStructFieldNames.get(i));
sb.append("`");
sb.append(":");
sb.append(escapeHiveType(allStructFieldTypeInfos.get(i).getTypeName()));
}
sb.append(">");
return sb.toString();
} else // Union
if (ObjectInspector.Category.UNION.equals(typeInfo.getCategory())) {
UnionTypeInfo unionTypeInfo = (UnionTypeInfo) typeInfo;
List<TypeInfo> allUnionObjectTypeInfos = unionTypeInfo.getAllUnionObjectTypeInfos();
StringBuilder sb = new StringBuilder();
sb.append(serdeConstants.UNION_TYPE_NAME + "<");
for (int i = 0; i < allUnionObjectTypeInfos.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(escapeHiveType(allUnionObjectTypeInfos.get(i).getTypeName()));
}
sb.append(">");
return sb.toString();
} else {
throw new RuntimeException("Unknown type encountered: " + type);
}
}
use of org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo in project haivvreo by jghoman.
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 HaivvreoException("Don't yet support this type: " + ti);
ObjectInspector result;
switch(ti.getCategory()) {
case PRIMITIVE:
PrimitiveTypeInfo pti = (PrimitiveTypeInfo) ti;
result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti.getPrimitiveCategory());
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 HaivvreoException("No Hive categories matched: " + ti);
}
return result;
}
use of org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo in project hive by apache.
the class BatchToRowReader method nextUnion.
private UnionType nextUnion(ColumnVector vector, int row, UnionTypeInfo schema, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
List<TypeInfo> childrenTypes = schema.getAllUnionObjectTypeInfos();
UnionType result = createUnionObject(childrenTypes, previous);
UnionColumnVector union = (UnionColumnVector) vector;
byte tag = (byte) union.tags[row];
setUnion(result, tag, nextValue(union.fields[tag], row, childrenTypes.get(tag), getUnionField(result)));
return result;
} else {
return null;
}
}
use of org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo in project hive by apache.
the class Serializer method writeUnion.
private void writeUnion(FieldVector arrowVector, ColumnVector hiveVector, TypeInfo typeInfo, int size, VectorizedRowBatch vectorizedRowBatch, boolean isNative) {
final UnionTypeInfo unionTypeInfo = (UnionTypeInfo) typeInfo;
final List<TypeInfo> objectTypeInfos = unionTypeInfo.getAllUnionObjectTypeInfos();
final UnionColumnVector hiveUnionVector = (UnionColumnVector) hiveVector;
final ColumnVector[] hiveObjectVectors = hiveUnionVector.fields;
final int tag = hiveUnionVector.tags[0];
final ColumnVector hiveObjectVector = hiveObjectVectors[tag];
final TypeInfo objectTypeInfo = objectTypeInfos.get(tag);
write(arrowVector, hiveObjectVector, objectTypeInfo, size, vectorizedRowBatch, isNative);
}
Aggregations