use of org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector in project hive by apache.
the class LazyObjectInspectorFactory method getLazySimpleStructObjectInspector.
public static LazySimpleStructObjectInspector getLazySimpleStructObjectInspector(List<String> structFieldNames, List<ObjectInspector> structFieldObjectInspectors, List<String> structFieldComments, byte separator, LazyObjectInspectorParameters lazyParams, ObjectInspectorOptions option) {
ArrayList<Object> signature = new ArrayList<Object>();
signature.add(structFieldNames);
signature.add(structFieldObjectInspectors);
signature.add(Byte.valueOf(separator));
signature.add(lazyParams.getNullSequence().toString());
signature.add(Boolean.valueOf(lazyParams.isLastColumnTakesRest()));
LazyObjectInspectorFactory.addCommonLazyParamsToSignature(lazyParams, signature);
signature.add(option);
if (structFieldComments != null) {
signature.add(structFieldComments);
}
LazySimpleStructObjectInspector result = cachedLazySimpleStructObjectInspector.get(signature);
if (result == null) {
switch(option) {
case JAVA:
result = new LazySimpleStructObjectInspector(structFieldNames, structFieldObjectInspectors, structFieldComments, separator, lazyParams);
break;
case AVRO:
result = new AvroLazyObjectInspector(structFieldNames, structFieldObjectInspectors, structFieldComments, separator, lazyParams);
break;
default:
throw new IllegalArgumentException("Illegal ObjectInspector type [" + option + "]");
}
LazySimpleStructObjectInspector prev = cachedLazySimpleStructObjectInspector.putIfAbsent(signature, result);
if (prev != null) {
result = prev;
}
}
return result;
}
use of org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector in project hive by apache.
the class LazySimpleStructObjectInspector method getStructFieldData.
// With Data
@Override
public Object getStructFieldData(Object data, StructField fieldRef) {
if (data == null) {
return null;
}
StructObject struct = (StructObject) data;
MyField f = (MyField) fieldRef;
int fieldID = f.getFieldID();
assert (fieldID >= 0 && fieldID < fields.size());
ObjectInspector oi = f.getFieldObjectInspector();
if (oi instanceof AvroLazyObjectInspector) {
return ((AvroLazyObjectInspector) oi).getStructFieldData(data, fieldRef);
}
if (oi instanceof MapObjectInspector) {
ObjectInspector valueOI = ((MapObjectInspector) oi).getMapValueObjectInspector();
if (valueOI instanceof AvroLazyObjectInspector) {
return ((AvroLazyObjectInspector) valueOI).getStructFieldData(data, fieldRef);
}
}
return struct.getField(fieldID);
}
use of org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector in project hive by apache.
the class AvroHBaseValueFactory method initAvroObjectInspector.
/**
* Recursively initialize the {@link AvroLazyObjectInspector} and all its nested ois
*
* @param oi ObjectInspector to be recursively initialized
* @param schema {@link Schema} to be initialized with
* @param schemaRetriever class to be used to retrieve schema
*/
private void initAvroObjectInspector(ObjectInspector oi) {
// Check for a list. If found, recursively init its members
if (oi instanceof ListObjectInspector) {
ListObjectInspector loi = (ListObjectInspector) oi;
initAvroObjectInspector(loi.getListElementObjectInspector());
return;
}
// Check for a nested message. If found, set the schema, else return.
if (!(oi instanceof AvroLazyObjectInspector)) {
return;
}
AvroLazyObjectInspector aoi = (AvroLazyObjectInspector) oi;
aoi.setSchemaRetriever(avroSchemaRetriever);
aoi.setReaderSchema(schema);
// objectinspector
for (StructField field : aoi.getAllStructFieldRefs()) {
initAvroObjectInspector(field.getFieldObjectInspector());
}
}
use of org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector 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()));
}
Aggregations