Search in sources :

Example 36 with Deserializer

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);
}
Also used : SerDe(org.apache.hadoop.hive.serde2.SerDe) WindowingException(com.sap.hadoop.windowing.WindowingException) Properties(java.util.Properties) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 37 with Deserializer

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));
}
Also used : HashMap(java.util.HashMap) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) NullWritable(org.apache.hadoop.io.NullWritable) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) Writable(org.apache.hadoop.io.Writable) DoubleWritable(org.apache.hadoop.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) BytesWritable(org.apache.hadoop.io.BytesWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) ShortWritable(org.apache.hadoop.io.ShortWritable) IntWritable(org.apache.hadoop.io.IntWritable) HiveBaseCharWritable(org.apache.hadoop.hive.serde2.io.HiveBaseCharWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) Text(org.apache.hadoop.io.Text) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) LazyPrimitive(org.apache.hadoop.hive.serde2.lazy.LazyPrimitive) LazyNonPrimitive(org.apache.hadoop.hive.serde2.lazy.LazyNonPrimitive) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Aggregations

Deserializer (org.apache.hadoop.hive.serde2.Deserializer)19 ArrayList (java.util.ArrayList)14 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)14 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)13 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)10 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)10 IOException (java.io.IOException)7 Properties (java.util.Properties)7 Path (org.apache.hadoop.fs.Path)6 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)6 Configuration (org.apache.hadoop.conf.Configuration)5 HashMap (java.util.HashMap)4 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)4 PartitionDesc (org.apache.hadoop.hive.ql.plan.PartitionDesc)4 LazySimpleSerDe (org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe)4 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)4 List (java.util.List)3 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)3 TableDesc (org.apache.hadoop.hive.ql.plan.TableDesc)3 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)3