Search in sources :

Example 1 with LazyObject

use of org.apache.hadoop.hive.serde2.lazy.LazyObject in project presto by prestodb.

the class ColumnarBinaryHiveRecordCursor method parseObjectColumn.

private void parseObjectColumn(int column, byte[] bytes, int start, int length) {
    checkState(VALID_HIVE_STRUCTURAL_CATEGORIES.contains(hiveTypes[column].getCategory()), "%s is not a valid STRUCTURAL type", hiveTypes[column]);
    if (length == 0) {
        nulls[column] = true;
    } else {
        nulls[column] = false;
        LazyBinaryObject<? extends ObjectInspector> lazyObject = LazyBinaryFactory.createLazyBinaryObject(fieldInspectors[column]);
        ByteArrayRef byteArrayRef = new ByteArrayRef();
        byteArrayRef.setData(bytes);
        lazyObject.init(byteArrayRef, start, length);
        objects[column] = getBlockObject(types[column], lazyObject.getObject(), fieldInspectors[column]);
    }
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 2 with LazyObject

use of org.apache.hadoop.hive.serde2.lazy.LazyObject in project presto by prestodb.

the class ColumnarTextHiveRecordCursor method parseObjectColumn.

private void parseObjectColumn(int column, byte[] bytes, int start, int length) {
    boolean wasNull;
    if (length == "\\N".length() && bytes[start] == '\\' && bytes[start + 1] == 'N') {
        wasNull = true;
    } else {
        LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldInspectors[column]);
        ByteArrayRef byteArrayRef = new ByteArrayRef();
        byteArrayRef.setData(bytes);
        lazyObject.init(byteArrayRef, start, length);
        objects[column] = getBlockObject(types[column], lazyObject.getObject(), fieldInspectors[column]);
        wasNull = false;
    }
    nulls[column] = wasNull;
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 3 with LazyObject

use of org.apache.hadoop.hive.serde2.lazy.LazyObject in project hive by apache.

the class HBaseCompositeKey method toLazyObject.

/**
 * Create an initialize a {@link LazyObject} with the given bytes for the given fieldID.
 *
 * @param fieldID
 *          field for which the object is to be created
 * @param bytes
 *          value with which the object is to be initialized with
 * @return initialized {@link LazyObject}
 */
public LazyObject<? extends ObjectInspector> toLazyObject(int fieldID, byte[] bytes) {
    ObjectInspector fieldOI = oi.getAllStructFieldRefs().get(fieldID).getFieldObjectInspector();
    LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldOI);
    ByteArrayRef ref = new ByteArrayRef();
    ref.setData(bytes);
    // initialize the lazy object
    lazyObject.init(ref, 0, ref.getData().length);
    return lazyObject;
}
Also used : LazySimpleStructObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 4 with LazyObject

use of org.apache.hadoop.hive.serde2.lazy.LazyObject in project hive by apache.

the class AvroLazyObjectInspector method toLazyMapObject.

/**
 * Convert the given object to a lazy object using the given {@link ObjectInspector}
 *
 * @param obj Object to be converted to a {@link LazyObject}
 * @param oi ObjectInspector used for the conversion
 * @return the created {@link LazyObject lazy object}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object toLazyMapObject(Object obj, ObjectInspector objectInspector) {
    if (obj == null) {
        return null;
    }
    // avro guarantees that the key will be of type string. So we just need to worry about
    // deserializing the value here
    LazyMap lazyMap = (LazyMap) LazyFactory.createLazyObject(objectInspector);
    Map map = lazyMap.getMap();
    Map<Object, Object> origMap = (Map) obj;
    ObjectInspector keyObjectInspector = ((MapObjectInspector) objectInspector).getMapKeyObjectInspector();
    ObjectInspector valueObjectInspector = ((MapObjectInspector) objectInspector).getMapValueObjectInspector();
    for (Entry entry : origMap.entrySet()) {
        Object value = entry.getValue();
        map.put(toLazyPrimitiveObject(entry.getKey(), keyObjectInspector), toLazyObject(value, valueObjectInspector));
    }
    return lazyMap;
}
Also used : LazyUnionObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) LazyListObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector) LazySimpleStructObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LazyMapObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) Entry(java.util.Map.Entry) LazyMapObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) LazyMap(org.apache.hadoop.hive.serde2.lazy.LazyMap) LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject) Map(java.util.Map) LazyMap(org.apache.hadoop.hive.serde2.lazy.LazyMap)

Example 5 with LazyObject

use of org.apache.hadoop.hive.serde2.lazy.LazyObject in project hive by apache.

the class LazyHBaseCellMap method getMapValueElement.

/**
 * Get the value in the map for the given key.
 *
 * @param key
 * @return
 */
@Override
public Object getMapValueElement(Object key) {
    if (!getParsed()) {
        parse();
    }
    for (Map.Entry<Object, Object> entry : cachedMap.entrySet()) {
        LazyPrimitive<?, ?> lazyKeyI = (LazyPrimitive<?, ?>) entry.getKey();
        // getWritableObject() will convert LazyPrimitive to actual primitive
        // writable objects.
        Object keyI = lazyKeyI.getWritableObject();
        if (keyI == null) {
            continue;
        }
        if (keyI.equals(key)) {
            // Got a match, return the value
            Object _value = entry.getValue();
            // Else return it as it is.
            if (_value instanceof LazyObject) {
                LazyObject<?> v = (LazyObject<?>) entry.getValue();
                return v == null ? v : v.getObject();
            } else {
                return _value;
            }
        }
    }
    return null;
}
Also used : LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject) LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject) LazyMap(org.apache.hadoop.hive.serde2.lazy.LazyMap) NavigableMap(java.util.NavigableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LazyPrimitive(org.apache.hadoop.hive.serde2.lazy.LazyPrimitive)

Aggregations

ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)9 LazySimpleStructObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector)8 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)8 LazyObject (org.apache.hadoop.hive.serde2.lazy.LazyObject)7 LazyMapObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector)6 Map (java.util.Map)4 LazyListObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector)4 LazyUnionObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector)4 ArrayList (java.util.ArrayList)3 LazyMap (org.apache.hadoop.hive.serde2.lazy.LazyMap)3 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)3 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 LazyPrimitive (org.apache.hadoop.hive.serde2.lazy.LazyPrimitive)2 ListTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo)2 MapTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)2 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)2 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)2 UnionTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)2