use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef 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.ByteArrayRef 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.ByteArrayRef in project hive by apache.
the class TestAvroLazyObjectInspector method testEmptyData.
@Test
public void testEmptyData() {
List<String> fieldNames = new ArrayList<String>();
fieldNames.add("myField");
List<ObjectInspector> ois = new ArrayList<ObjectInspector>();
ois.add(LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, new Byte((byte) 0)));
AvroLazyObjectInspector aloi = new AvroLazyObjectInspector(fieldNames, ois, null, (byte) 0, new Text(), false, false, (byte) 0);
LazyStruct lazyStruct = new LazyStruct(LazyObjectInspectorFactory.getLazySimpleStructObjectInspector(fieldNames, ois, (byte) 0, new Text(), false, false, (byte) 0));
ByteArrayRef byteArrayRef = new ByteArrayRef();
// set data to empty explicitly
byteArrayRef.setData(new byte[0]);
lazyStruct.init(byteArrayRef, 0, 0);
assertNull(aloi.getStructFieldData(lazyStruct, new TestStructField()));
}
use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef 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.ByteArrayRef in project hive by apache.
the class LazyDioBoolean method init.
/* (non-Javadoc)
* This provides a LazyBoolean like class which can be initialized from data stored in a
* binary format.
*
* @see org.apache.hadoop.hive.serde2.lazy.LazyObject#init
* (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef, int, int)
*/
@Override
public void init(ByteArrayRef bytes, int start, int length) {
boolean value = false;
try {
in = new ByteStream.Input(bytes.getData(), start, length);
din = new DataInputStream(in);
value = din.readBoolean();
data.set(value);
isNull = false;
} catch (IOException e) {
isNull = true;
} finally {
try {
din.close();
} catch (IOException e) {
// swallow exception
}
try {
in.close();
} catch (IOException e) {
// swallow exception
}
}
}
Aggregations