use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project metacat by Netflix.
the class HiveTypeConverter method getCanonicalType.
/**
* Returns the canonical type.
*
* @param fieldInspector inspector
* @return type
*/
Type getCanonicalType(final ObjectInspector fieldInspector) {
switch(fieldInspector.getCategory()) {
case PRIMITIVE:
return getPrimitiveType(fieldInspector);
case MAP:
final MapObjectInspector mapObjectInspector = TypeUtils.checkType(fieldInspector, MapObjectInspector.class, "fieldInspector");
final Type keyType = getCanonicalType(mapObjectInspector.getMapKeyObjectInspector());
final Type valueType = getCanonicalType(mapObjectInspector.getMapValueObjectInspector());
if (keyType == null || valueType == null) {
return null;
}
return TypeRegistry.getTypeRegistry().getParameterizedType(TypeEnum.MAP, ImmutableList.of(keyType.getTypeSignature(), valueType.getTypeSignature()), ImmutableList.of());
case LIST:
final ListObjectInspector listObjectInspector = TypeUtils.checkType(fieldInspector, ListObjectInspector.class, "fieldInspector");
final Type elementType = getCanonicalType(listObjectInspector.getListElementObjectInspector());
if (elementType == null) {
return null;
}
return TypeRegistry.getTypeRegistry().getParameterizedType(TypeEnum.ARRAY, ImmutableList.of(elementType.getTypeSignature()), ImmutableList.of());
case STRUCT:
final StructObjectInspector structObjectInspector = TypeUtils.checkType(fieldInspector, StructObjectInspector.class, "fieldInspector");
final List<TypeSignature> fieldTypes = new ArrayList<>();
final List<Object> fieldNames = new ArrayList<>();
for (StructField field : structObjectInspector.getAllStructFieldRefs()) {
fieldNames.add(field.getFieldName());
final Type fieldType = getCanonicalType(field.getFieldObjectInspector());
if (fieldType == null) {
return null;
}
fieldTypes.add(fieldType.getTypeSignature());
}
return TypeRegistry.getTypeRegistry().getParameterizedType(TypeEnum.ROW, fieldTypes, fieldNames);
default:
log.info("Currently unsupported type {}, returning Unknown type", fieldInspector.getTypeName());
return BaseType.UNKNOWN;
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project asterixdb by apache.
the class HiveRecordParser method parseUnorderedList.
private void parseUnorderedList(AUnorderedListType uoltype, Object obj, ListObjectInspector oi) throws IOException {
UnorderedListBuilder unorderedListBuilder = getUnorderedListBuilder();
IAType itemType = null;
if (uoltype != null)
itemType = uoltype.getItemType();
byte tagByte = itemType.getTypeTag().serialize();
unorderedListBuilder.reset(uoltype);
int n = oi.getListLength(obj);
for (int i = 0; i < n; i++) {
Object element = oi.getListElement(obj, i);
ObjectInspector eoi = oi.getListElementObjectInspector();
if (element == null) {
throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_VALUE_IN_LIST);
}
listItemBuffer.reset();
final DataOutput dataOutput = listItemBuffer.getDataOutput();
dataOutput.writeByte(tagByte);
parseItem(itemType, element, eoi, dataOutput, true);
unorderedListBuilder.addItem(listItemBuffer);
}
unorderedListBuilder.write(fieldValueBuffer.getDataOutput(), true);
}
Aggregations