Search in sources :

Example 1 with WriteNullsProtocol

use of org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol 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 2 with WriteNullsProtocol

use of org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol 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

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 WriteNullsProtocol (org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)1 TList (org.apache.thrift.protocol.TList)1 TMap (org.apache.thrift.protocol.TMap)1