use of org.apache.hadoop.hive.serde2.Deserializer in project SQLWindowing by hbutani.
the class QueryDefDeserializer method visit.
/*
* 1. Determine the serde properties from the hive table definition
* 2. Retrieve the deserializer using the serde class name and
* initialize it using the serdeproperties
* 3. setup the serde and OI on the hive table definition The OI is
* used to evaluate expressions in the next PTF in the
* chain. This OI is constructed from the hive meta table info.
* 4. We add the hive table definition to the input
* map on the query translation info.
*/
@Override
public void visit(HiveTableDef hiveTable) throws WindowingException {
this.qInDef = hiveTable;
String serDeClassName = hiveTable.getTableSerdeClassName();
Properties serDeProps = new Properties();
Map<String, String> serdePropsMap = hiveTable.getTableSerdeProps();
for (String serdeName : serdePropsMap.keySet()) {
serDeProps.setProperty(serdeName, serdePropsMap.get(serdeName));
}
try {
SerDe serDe = (SerDe) SerDeUtils.lookupDeserializer(serDeClassName);
serDe.initialize(hConf, serDeProps);
hiveTable.setSerde(serDe);
hiveTable.setOI((StructObjectInspector) serDe.getObjectInspector());
} catch (SerDeException se) {
throw new WindowingException(se);
}
tInfo.addInput(hiveTable);
inputInfo = tInfo.getInputInfo(hiveTable);
}
use of org.apache.hadoop.hive.serde2.Deserializer 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