use of org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo in project flink by apache.
the class HiveInspectors method getObjectInspector.
public static ObjectInspector getObjectInspector(TypeInfo type) {
switch(type.getCategory()) {
case PRIMITIVE:
PrimitiveTypeInfo primitiveType = (PrimitiveTypeInfo) type;
return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(primitiveType);
case LIST:
ListTypeInfo listType = (ListTypeInfo) type;
return ObjectInspectorFactory.getStandardListObjectInspector(getObjectInspector(listType.getListElementTypeInfo()));
case MAP:
MapTypeInfo mapType = (MapTypeInfo) type;
return ObjectInspectorFactory.getStandardMapObjectInspector(getObjectInspector(mapType.getMapKeyTypeInfo()), getObjectInspector(mapType.getMapValueTypeInfo()));
case STRUCT:
StructTypeInfo structType = (StructTypeInfo) type;
List<TypeInfo> fieldTypes = structType.getAllStructFieldTypeInfos();
List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>();
for (TypeInfo fieldType : fieldTypes) {
fieldInspectors.add(getObjectInspector(fieldType));
}
return ObjectInspectorFactory.getStandardStructObjectInspector(structType.getAllStructFieldNames(), fieldInspectors);
default:
throw new CatalogException("Unsupported Hive type category " + type.getCategory());
}
}
use of org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo in project flink by apache.
the class HiveTypeUtil method toFlinkType.
/**
* Convert Hive data type to a Flink data type.
*
* @param hiveType a Hive data type
* @return the corresponding Flink data type
*/
public static DataType toFlinkType(TypeInfo hiveType) {
checkNotNull(hiveType, "hiveType cannot be null");
switch(hiveType.getCategory()) {
case PRIMITIVE:
return toFlinkPrimitiveType((PrimitiveTypeInfo) hiveType);
case LIST:
ListTypeInfo listTypeInfo = (ListTypeInfo) hiveType;
return DataTypes.ARRAY(toFlinkType(listTypeInfo.getListElementTypeInfo()));
case MAP:
MapTypeInfo mapTypeInfo = (MapTypeInfo) hiveType;
return DataTypes.MAP(toFlinkType(mapTypeInfo.getMapKeyTypeInfo()), toFlinkType(mapTypeInfo.getMapValueTypeInfo()));
case STRUCT:
StructTypeInfo structTypeInfo = (StructTypeInfo) hiveType;
List<String> names = structTypeInfo.getAllStructFieldNames();
List<TypeInfo> typeInfos = structTypeInfo.getAllStructFieldTypeInfos();
DataTypes.Field[] fields = new DataTypes.Field[names.size()];
for (int i = 0; i < fields.length; i++) {
fields[i] = DataTypes.FIELD(names.get(i), toFlinkType(typeInfos.get(i)));
}
return DataTypes.ROW(fields);
default:
throw new UnsupportedOperationException(String.format("Flink doesn't support Hive data type %s yet.", hiveType));
}
}
use of org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo in project mongo-hadoop by mongodb.
the class BSONSerDe method deserializeList.
/**
* Deserialize a List with the same listElemTypeInfo for its elements
* @param value the value for which to get the Hive representation
* @param valueTypeInfo a description of the value's type
* @param ext the field name
* @return the Hive representation of the value
*/
private Object deserializeList(final Object value, final ListTypeInfo valueTypeInfo, final String ext) {
BasicBSONList list = (BasicBSONList) value;
TypeInfo listElemTypeInfo = valueTypeInfo.getListElementTypeInfo();
for (int i = 0; i < list.size(); i++) {
list.set(i, deserializeField(list.get(i), listElemTypeInfo, ext));
}
return list.toArray();
}
use of org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo in project hive by apache.
the class DataWritableReadSupport method getProjectedType.
private static Type getProjectedType(TypeInfo colType, Type fieldType) {
switch(colType.getCategory()) {
case STRUCT:
List<Type> groupFields = getProjectedGroupFields(fieldType.asGroupType(), ((StructTypeInfo) colType).getAllStructFieldNames(), ((StructTypeInfo) colType).getAllStructFieldTypeInfos());
Type[] typesArray = groupFields.toArray(new Type[0]);
return Types.buildGroup(fieldType.getRepetition()).addFields(typesArray).named(fieldType.getName());
case LIST:
TypeInfo elemType = ((ListTypeInfo) colType).getListElementTypeInfo();
if (elemType.getCategory() == ObjectInspector.Category.STRUCT) {
Type subFieldType = fieldType.asGroupType().getType(0);
if (!subFieldType.isPrimitive()) {
String subFieldName = subFieldType.getName();
Text name = new Text(subFieldName);
if (name.equals(ParquetHiveSerDe.ARRAY) || name.equals(ParquetHiveSerDe.LIST)) {
subFieldType = new GroupType(Repetition.REPEATED, subFieldName, getProjectedType(elemType, subFieldType.asGroupType().getType(0)));
} else {
subFieldType = getProjectedType(elemType, subFieldType);
}
return Types.buildGroup(Repetition.OPTIONAL).as(LogicalTypeAnnotation.listType()).addFields(subFieldType).named(fieldType.getName());
}
}
break;
default:
}
return fieldType;
}
use of org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo in project hive by apache.
the class ExprNodeConverter method visitFieldAccess.
/**
* TODO: Handle 1) cast 2), Windowing Agg Call
*/
@Override
public /*
* Handles expr like struct(key,value).key
* Follows same rules as TypeCheckProcFactory::getXpathOrFuncExprNodeDesc()
* which is equivalent version of parsing such an expression from AST
*/
ExprNodeDesc visitFieldAccess(RexFieldAccess fieldAccess) {
ExprNodeDesc parent = fieldAccess.getReferenceExpr().accept(this);
String child = fieldAccess.getField().getName();
TypeInfo parentType = parent.getTypeInfo();
// Allow accessing a field of list element structs directly from a list
boolean isList = (parentType.getCategory() == ObjectInspector.Category.LIST);
if (isList) {
parentType = ((ListTypeInfo) parentType).getListElementTypeInfo();
}
TypeInfo t = ((StructTypeInfo) parentType).getStructFieldTypeInfo(child);
return new ExprNodeFieldDesc(t, parent, child, isList);
}
Aggregations