Search in sources :

Example 26 with ListObjectInspector

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);
}
Also used : StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) ObjectInspectorFactory.getStandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspectorFactory.getStandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector)

Example 27 with ListObjectInspector

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);
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) IntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector) BooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector) ShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) FloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) ByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector) DoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector) TimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 28 with ListObjectInspector

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;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ArrayWritable(org.apache.hadoop.io.ArrayWritable) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ChunkRowIterator(org.apache.carbondata.core.scan.result.iterator.ChunkRowIterator) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) Writable(org.apache.hadoop.io.Writable) LongWritable(org.apache.hadoop.io.LongWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) ArrayWritable(org.apache.hadoop.io.ArrayWritable) IntWritable(org.apache.hadoop.io.IntWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with ListObjectInspector

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;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) IntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector) HiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) DoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector) TimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector) DateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector) ArrayWritable(org.apache.hadoop.io.ArrayWritable) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Writable(org.apache.hadoop.io.Writable) LongWritable(org.apache.hadoop.io.LongWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) ArrayWritable(org.apache.hadoop.io.ArrayWritable) IntWritable(org.apache.hadoop.io.IntWritable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with ListObjectInspector

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;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) LazyBinaryListObjectInspector(org.apache.hadoop.hive.serde2.lazybinary.objectinspector.LazyBinaryListObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) LazyBinaryListObjectInspector(org.apache.hadoop.hive.serde2.lazybinary.objectinspector.LazyBinaryListObjectInspector)

Aggregations

ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)48 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)35 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)34 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)26 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)25 ArrayList (java.util.ArrayList)23 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)17 TimestampObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector)17 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)16 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)16 ShortObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector)16 ByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)15 FloatObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector)15 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)15 BooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)14 HiveDecimalObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector)14 List (java.util.List)13 BinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector)13 DateObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector)13 Map (java.util.Map)11