Search in sources :

Example 31 with SerDeException

use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.

the class DynamicSerDe method serialize.

@Override
public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException {
    try {
        bos_.reset();
        bt.serialize(obj, objInspector, oprot_);
        oprot_.getTransport().flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw new SerDeException(e);
    }
    ret.set(bos_.getData(), 0, bos_.getLength());
    return ret;
}
Also used : SerDeException(org.apache.hadoop.hive.serde2.SerDeException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 32 with SerDeException

use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.

the class DynamicSerDeTypeBool method serialize.

@Override
public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
    BooleanObjectInspector poi = (BooleanObjectInspector) oi;
    oprot.writeBool(poi.get(o));
}
Also used : BooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)

Example 33 with SerDeException

use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.

the class DynamicSerDeTypeByte method serialize.

@Override
public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
    ByteObjectInspector poi = (ByteObjectInspector) oi;
    oprot.writeByte(poi.get(o));
}
Also used : ByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)

Example 34 with SerDeException

use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.

the class DynamicSerDeTypeList method serialize.

@Override
public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
    ListObjectInspector loi = (ListObjectInspector) oi;
    ObjectInspector elementObjectInspector = loi.getListElementObjectInspector();
    DynamicSerDeTypeBase mt = getElementType();
    WriteNullsProtocol nullProtocol = (oprot instanceof WriteNullsProtocol) ? (WriteNullsProtocol) oprot : null;
    if (o instanceof List) {
        List<?> list = (List<?>) o;
        oprot.writeListBegin(new TList(mt.getType(), list.size()));
        for (Object element : list) {
            if (element == null) {
                assert (nullProtocol != null);
                nullProtocol.writeNull();
            } else {
                mt.serialize(element, elementObjectInspector, oprot);
            }
        }
    } else {
        Object[] list = (Object[]) o;
        oprot.writeListBegin(new TList(mt.getType(), list.length));
        for (Object element : list) {
            if (element == null && nullProtocol != null) {
                assert (nullProtocol != null);
                nullProtocol.writeNull();
            } else {
                mt.serialize(element, elementObjectInspector, oprot);
            }
        }
    }
    // in theory, the below call isn't needed in non thrift_mode, but let's not
    // get too crazy
    oprot.writeListEnd();
}
Also used : TList(org.apache.thrift.protocol.TList) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) WriteNullsProtocol(org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol) TList(org.apache.thrift.protocol.TList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 35 with SerDeException

use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.

the class DynamicSerDeTypeMap method serialize.

@Override
public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
    DynamicSerDeTypeBase keyType = getKeyType();
    DynamicSerDeTypeBase valueType = getValueType();
    WriteNullsProtocol nullProtocol = (oprot instanceof WriteNullsProtocol) ? (WriteNullsProtocol) oprot : null;
    assert (oi.getCategory() == ObjectInspector.Category.MAP);
    MapObjectInspector moi = (MapObjectInspector) oi;
    ObjectInspector koi = moi.getMapKeyObjectInspector();
    ObjectInspector voi = moi.getMapValueObjectInspector();
    Map<?, ?> map = moi.getMap(o);
    serializeMap = new TMap(keyType.getType(), valueType.getType(), map.size());
    oprot.writeMapBegin(serializeMap);
    for (Object element : map.entrySet()) {
        Map.Entry it = (Map.Entry) element;
        Object key = it.getKey();
        Object value = it.getValue();
        keyType.serialize(key, koi, oprot);
        if (value == null) {
            assert (nullProtocol != null);
            nullProtocol.writeNull();
        } else {
            valueType.serialize(value, voi, oprot);
        }
    }
    // in theory, the below call isn't needed in non thrift_mode, but let's not
    // get too crazy
    oprot.writeMapEnd();
}
Also used : MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) WriteNullsProtocol(org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol) Map(java.util.Map) HashMap(java.util.HashMap) TMap(org.apache.thrift.protocol.TMap) TMap(org.apache.thrift.protocol.TMap)

Aggregations

SerDeException (org.apache.hadoop.hive.serde2.SerDeException)124 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)108 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)100 ArrayList (java.util.ArrayList)98 Properties (java.util.Properties)59 Test (org.junit.Test)59 Configuration (org.apache.hadoop.conf.Configuration)52 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)52 Text (org.apache.hadoop.io.Text)50 IOException (java.io.IOException)37 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)33 Schema (org.apache.avro.Schema)31 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)31 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)28 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)28 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)24 Put (org.apache.hadoop.hbase.client.Put)22 LazySerDeParameters (org.apache.hadoop.hive.serde2.lazy.LazySerDeParameters)22 IntWritable (org.apache.hadoop.io.IntWritable)22 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)21