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;
}
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;
}
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);
}
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.");
}
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;
}
Aggregations