Search in sources :

Example 6 with LazyObject

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

the class AvroLazyObjectInspector method toLazyPrimitiveObject.

/**
   * 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}
   * */
private LazyObject<? extends ObjectInspector> toLazyPrimitiveObject(Object obj, ObjectInspector oi) {
    if (obj == null) {
        return null;
    }
    LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(oi);
    ByteArrayRef ref = new ByteArrayRef();
    String objAsString = obj.toString().trim();
    ref.setData(objAsString.getBytes());
    // initialize the lazy object
    lazyObject.init(ref, 0, ref.getData().length);
    return lazyObject;
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 7 with LazyObject

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

the class AvroLazyObjectInspector method toLazyListObject.

/**
   * 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}
   * */
private Object toLazyListObject(Object obj, ObjectInspector objectInspector) {
    if (obj == null) {
        return null;
    }
    List<?> listObj = (List<?>) obj;
    LazyArray retList = (LazyArray) LazyFactory.createLazyObject(objectInspector);
    List<Object> lazyList = retList.getList();
    ObjectInspector listElementOI = ((ListObjectInspector) objectInspector).getListElementObjectInspector();
    for (int i = 0; i < listObj.size(); i++) {
        lazyList.add(toLazyObject(listObj.get(i), listElementOI));
    }
    return retList;
}
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) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) LazyListObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector) ArrayList(java.util.ArrayList) List(java.util.List) LazyArray(org.apache.hadoop.hive.serde2.lazy.LazyArray) LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject)

Example 8 with LazyObject

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

the class AvroLazyObjectInspector method toLazyUnionObject.

/**
   * 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}
   * */
private Object toLazyUnionObject(Object obj, ObjectInspector objectInspector) {
    if (obj == null) {
        return null;
    }
    if (!(objectInspector instanceof LazyUnionObjectInspector)) {
        throw new IllegalArgumentException("Invalid objectinspector found. Expected LazyUnionObjectInspector, Found " + objectInspector.getClass());
    }
    StandardUnion standardUnion = (StandardUnion) obj;
    LazyUnionObjectInspector lazyUnionOI = (LazyUnionObjectInspector) objectInspector;
    // Grab the tag and the field
    byte tag = standardUnion.getTag();
    Object field = standardUnion.getObject();
    ObjectInspector fieldOI = lazyUnionOI.getObjectInspectors().get(tag);
    // convert to lazy object
    Object convertedObj = null;
    if (field != null) {
        convertedObj = toLazyObject(field, fieldOI);
    }
    if (convertedObj == null) {
        return null;
    }
    return new LazyUnion(lazyUnionOI, tag, convertedObj);
}
Also used : LazyUnionObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector) 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) StandardUnion(org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion) LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject) LazyUnion(org.apache.hadoop.hive.serde2.lazy.LazyUnion)

Example 9 with LazyObject

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

the class LazyFactory method createLazyObjectInspector.

/**
   * Create a hierarchical ObjectInspector for LazyObject with the given typeInfo.
   *
   * @param typeInfo The type information for the LazyObject
   * @param separator The array of separators for delimiting each level
   * @param separatorIndex The current level (for separators). List(array), struct uses 1 level of
   *          separator, and map uses 2 levels: the first one for delimiting entries, the second one
   *          for delimiting key and values.
   * @param lazyParams Params for lazy types
   * @param option the {@link ObjectInspectorOption}
   * @return The ObjectInspector
   * @throws SerDeException
   */
public static ObjectInspector createLazyObjectInspector(TypeInfo typeInfo, int separatorIndex, LazyObjectInspectorParameters lazyParams, ObjectInspectorOptions option) throws SerDeException {
    ObjectInspector.Category c = typeInfo.getCategory();
    switch(c) {
        case PRIMITIVE:
            return LazyPrimitiveObjectInspectorFactory.getLazyObjectInspector((PrimitiveTypeInfo) typeInfo, lazyParams);
        case MAP:
            return LazyObjectInspectorFactory.getLazySimpleMapObjectInspector(createLazyObjectInspector(((MapTypeInfo) typeInfo).getMapKeyTypeInfo(), separatorIndex + 2, lazyParams, option), createLazyObjectInspector(((MapTypeInfo) typeInfo).getMapValueTypeInfo(), separatorIndex + 2, lazyParams, option), LazyUtils.getSeparator(lazyParams.getSeparators(), separatorIndex), LazyUtils.getSeparator(lazyParams.getSeparators(), separatorIndex + 1), lazyParams);
        case LIST:
            return LazyObjectInspectorFactory.getLazySimpleListObjectInspector(createLazyObjectInspector(((ListTypeInfo) typeInfo).getListElementTypeInfo(), separatorIndex + 1, lazyParams, option), LazyUtils.getSeparator(lazyParams.getSeparators(), separatorIndex), lazyParams);
        case STRUCT:
            StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
            List<String> fieldNames = structTypeInfo.getAllStructFieldNames();
            List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
            List<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>(fieldTypeInfos.size());
            for (int i = 0; i < fieldTypeInfos.size(); i++) {
                fieldObjectInspectors.add(createLazyObjectInspector(fieldTypeInfos.get(i), separatorIndex + 1, lazyParams, option));
            }
            return LazyObjectInspectorFactory.getLazySimpleStructObjectInspector(fieldNames, fieldObjectInspectors, null, LazyUtils.getSeparator(lazyParams.getSeparators(), separatorIndex), lazyParams, option);
        case UNION:
            UnionTypeInfo unionTypeInfo = (UnionTypeInfo) typeInfo;
            List<ObjectInspector> lazyOIs = new ArrayList<ObjectInspector>();
            for (TypeInfo uti : unionTypeInfo.getAllUnionObjectTypeInfos()) {
                lazyOIs.add(createLazyObjectInspector(uti, separatorIndex + 1, lazyParams, option));
            }
            return LazyObjectInspectorFactory.getLazyUnionObjectInspector(lazyOIs, LazyUtils.getSeparator(lazyParams.getSeparators(), separatorIndex), lazyParams);
    }
    throw new RuntimeException("Hive LazySerDe Internal error.");
}
Also used : LazyVoidObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyVoidObjectInspector) LazyUnionObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector) LazyDoubleObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyDoubleObjectInspector) LazyHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveDecimalObjectInspector) LazyIntObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyIntObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LazyMapObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector) LazyHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveVarcharObjectInspector) LazyBooleanObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyBooleanObjectInspector) LazyDateObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyDateObjectInspector) LazyListObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector) LazySimpleStructObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector) LazyLongObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyLongObjectInspector) LazyHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveIntervalDayTimeObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) LazyShortObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyShortObjectInspector) LazyFloatObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyFloatObjectInspector) LazyStringObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector) LazyTimestampObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyTimestampObjectInspector) LazyByteObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyByteObjectInspector) LazyHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveIntervalYearMonthObjectInspector) LazyHiveCharObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveCharObjectInspector) LazyBinaryObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyBinaryObjectInspector) ArrayList(java.util.ArrayList) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)

Example 10 with LazyObject

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

the class AccumuloCompositeRowId 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)

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 LazyListObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector)4 LazyUnionObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector)4 Map (java.util.Map)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 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 LazyPrimitive (org.apache.hadoop.hive.serde2.lazy.LazyPrimitive)2 List (java.util.List)1 Entry (java.util.Map.Entry)1 NavigableMap (java.util.NavigableMap)1 ColumnTuple (org.apache.hadoop.hive.accumulo.AccumuloHiveRow.ColumnTuple)1 LazyArray (org.apache.hadoop.hive.serde2.lazy.LazyArray)1 LazyUnion (org.apache.hadoop.hive.serde2.lazy.LazyUnion)1