use of org.apache.hadoop.hive.serde2.lazy.LazyNonPrimitive in project cdap by caskdata.
the class ObjectSerializer method serialize.
public Writable serialize(Object o, ObjectInspector objectInspector) {
//overwrite field names (as they get lost by Hive)
StructTypeInfo structTypeInfo = (StructTypeInfo) TypeInfoUtils.getTypeInfoFromObjectInspector(objectInspector);
structTypeInfo.setAllStructFieldNames(columnNames);
List<TypeInfo> info = structTypeInfo.getAllStructFieldTypeInfos();
List<String> names = structTypeInfo.getAllStructFieldNames();
Map<String, Object> recordMap = new HashMap<>();
List<Object> recordObjects = ((StructObjectInspector) objectInspector).getStructFieldsDataAsList(o);
for (int structIndex = 0; structIndex < info.size(); structIndex++) {
Object obj = recordObjects.get(structIndex);
TypeInfo objType = info.get(structIndex);
if (obj instanceof LazyNonPrimitive || obj instanceof LazyPrimitive) {
// In case the SerDe that deserialized the object is the one of a native table
recordMap.put(names.get(structIndex), fromLazyObject(objType, obj));
} else if (obj instanceof Writable) {
// Native tables sometimes introduce primitive Writable objects at this point
recordMap.put(names.get(structIndex), fromWritable((Writable) obj));
} else {
// In case the deserializer is the DatasetSerDe
recordMap.put(names.get(structIndex), serialize(obj, objType));
}
}
// TODO Improve serialization logic - CDAP-11
return new Text(GSON.toJson(recordMap));
}
Aggregations