Search in sources :

Example 1 with LazyUnionObjectInspector

use of org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector 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);
}
Also used : LazyUnionObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector) LazyUnionObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) LazyListObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector) LazySimpleStructObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LazyMapObjectInspector(org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) StandardUnion(org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion) LazyObject(org.apache.hadoop.hive.serde2.lazy.LazyObject) LazyUnion(org.apache.hadoop.hive.serde2.lazy.LazyUnion)

Aggregations

LazyObject (org.apache.hadoop.hive.serde2.lazy.LazyObject)1 LazyUnion (org.apache.hadoop.hive.serde2.lazy.LazyUnion)1 LazyListObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector)1 LazyMapObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector)1 LazySimpleStructObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector)1 LazyUnionObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 StandardUnion (org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion)1