Search in sources :

Example 1 with AvroLazyObjectInspector

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;
}
Also used : AvroLazyObjectInspector(org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector) ArrayList(java.util.ArrayList)

Example 2 with AvroLazyObjectInspector

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);
}
Also used : AvroLazyObjectInspector(org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) BaseStructObjectInspector(org.apache.hadoop.hive.serde2.BaseStructObjectInspector) AvroLazyObjectInspector(org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector) StructObject(org.apache.hadoop.hive.serde2.StructObject) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)

Example 3 with AvroLazyObjectInspector

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());
    }
}
Also used : AvroLazyObjectInspector(org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)

Example 4 with AvroLazyObjectInspector

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()));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) LazyStruct(org.apache.hadoop.hive.serde2.lazy.LazyStruct) Test(org.junit.Test)

Aggregations

AvroLazyObjectInspector (org.apache.hadoop.hive.serde2.avro.AvroLazyObjectInspector)3 ArrayList (java.util.ArrayList)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 BaseStructObjectInspector (org.apache.hadoop.hive.serde2.BaseStructObjectInspector)1 StructObject (org.apache.hadoop.hive.serde2.StructObject)1 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)1 LazyStruct (org.apache.hadoop.hive.serde2.lazy.LazyStruct)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)1 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1