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