use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project presto by prestodb.
the class TestHiveFileFormats method hasType.
public static boolean hasType(ObjectInspector objectInspector, PrimitiveCategory... types) {
if (objectInspector instanceof PrimitiveObjectInspector) {
PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) objectInspector;
PrimitiveCategory primitiveCategory = primitiveInspector.getPrimitiveCategory();
for (PrimitiveCategory type : types) {
if (primitiveCategory == type) {
return true;
}
}
return false;
}
if (objectInspector instanceof ListObjectInspector) {
ListObjectInspector listInspector = (ListObjectInspector) objectInspector;
return hasType(listInspector.getListElementObjectInspector(), types);
}
if (objectInspector instanceof MapObjectInspector) {
MapObjectInspector mapInspector = (MapObjectInspector) objectInspector;
return hasType(mapInspector.getMapKeyObjectInspector(), types) || hasType(mapInspector.getMapValueObjectInspector(), types);
}
if (objectInspector instanceof StructObjectInspector) {
for (StructField field : ((StructObjectInspector) objectInspector).getAllStructFieldRefs()) {
if (hasType(field.getFieldObjectInspector(), types)) {
return true;
}
}
return false;
}
throw new IllegalArgumentException("Unknown object inspector type " + objectInspector);
}
use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project asterixdb by apache.
the class HiveRecordParser method parseOrderedList.
private void parseOrderedList(AOrderedListType aOrderedListType, Object obj, ListObjectInspector foi) throws HyracksDataException {
OrderedListBuilder orderedListBuilder = getOrderedListBuilder();
IAType itemType = null;
if (aOrderedListType != null)
itemType = aOrderedListType.getItemType();
orderedListBuilder.reset(aOrderedListType);
int n = foi.getListLength(obj);
for (int i = 0; i < n; i++) {
Object element = foi.getListElement(obj, i);
ObjectInspector eoi = foi.getListElementObjectInspector();
if (element == null) {
throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_VALUE_IN_LIST);
}
parseItem(itemType, element, eoi, listItemBuffer.getDataOutput(), true);
orderedListBuilder.addItem(listItemBuffer);
}
orderedListBuilder.write(fieldValueBuffer.getDataOutput(), true);
}
use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project carbondata by apache.
the class CarbonHiveRecordReader method createArray.
private ArrayWritable createArray(Object obj, ListObjectInspector inspector) throws SerDeException {
List sourceArray = inspector.getList(obj);
ObjectInspector subInspector = inspector.getListElementObjectInspector();
List array = new ArrayList();
Iterator iterator;
if (sourceArray != null) {
for (iterator = sourceArray.iterator(); iterator.hasNext(); ) {
Object curObj = iterator.next();
Writable newObj = createObject(curObj, subInspector);
if (newObj != null) {
array.add(newObj);
}
}
}
if (array.size() > 0) {
ArrayWritable subArray = new ArrayWritable(((Writable) array.get(0)).getClass(), (Writable[]) array.toArray(new Writable[array.size()]));
return new ArrayWritable(Writable.class, new Writable[] { subArray });
}
return null;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project carbondata by apache.
the class CarbonHiveSerDe method createArray.
private ArrayWritable createArray(Object obj, ListObjectInspector inspector) throws SerDeException {
List sourceArray = inspector.getList(obj);
ObjectInspector subInspector = inspector.getListElementObjectInspector();
List array = new ArrayList();
Iterator iterator;
if (sourceArray != null) {
for (iterator = sourceArray.iterator(); iterator.hasNext(); ) {
Object curObj = iterator.next();
Writable newObj = createObject(curObj, subInspector);
if (newObj != null) {
array.add(newObj);
}
}
}
if (array.size() > 0) {
ArrayWritable subArray = new ArrayWritable(((Writable) array.get(0)).getClass(), (Writable[]) array.toArray(new Writable[array.size()]));
return new ArrayWritable(Writable.class, new Writable[] { subArray });
}
return null;
}
use of org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector in project hive by apache.
the class LazyBinaryArray method parse.
/**
* Parse the bytes and fill elementStart, elementLength, elementInited and
* elementIsNull.
*/
private void parse() {
byte[] bytes = this.bytes.getData();
// get the vlong that represents the map size
LazyBinaryUtils.readVInt(bytes, start, vInt);
arraySize = vInt.value;
if (0 == arraySize) {
parsed = true;
return;
}
// adjust arrays
adjustArraySize(arraySize);
// find out the null-bytes
int arryByteStart = start + vInt.length;
int nullByteCur = arryByteStart;
int nullByteEnd = arryByteStart + (arraySize + 7) / 8;
// the begin the real elements
int lastElementByteEnd = nullByteEnd;
// the list element object inspector
ObjectInspector listEleObjectInspector = ((ListObjectInspector) oi).getListElementObjectInspector();
// parsing elements one by one
for (int i = 0; i < arraySize; i++) {
elementIsNull[i] = true;
if ((bytes[nullByteCur] & (1 << (i % 8))) != 0) {
elementIsNull[i] = false;
LazyBinaryUtils.checkObjectByteInfo(listEleObjectInspector, bytes, lastElementByteEnd, recordInfo, vInt);
elementStart[i] = lastElementByteEnd + recordInfo.elementOffset;
elementLength[i] = recordInfo.elementSize;
lastElementByteEnd = elementStart[i] + elementLength[i];
}
// move onto the next null byte
if (7 == (i % 8)) {
nullByteCur++;
}
}
Arrays.fill(elementInited, 0, arraySize, false);
parsed = true;
}
Aggregations