diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java index 2ad06fc128..c9b29e3753 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorDeserializeRow.java @@ -1252,7 +1252,7 @@ private Object convertUnionRowColumn( final Object union = unionOI.create(); final int tag = deserializeRead.currentInt; unionOI.addField(union, new StandardUnion((byte) tag, - convertComplexFieldRowColumn(unionColumnVector.fields[tag], batchIndex, fields[tag]))); + convertComplexFieldRowColumn(unionColumnVector.fields[tag], batchIndex, fields[tag])), (byte) tag); deserializeRead.finishComplexVariableFieldsType(); return union; } diff --git ql/src/test/queries/clientpositive/orc_avro_partition_uniontype.q ql/src/test/queries/clientpositive/orc_avro_partition_uniontype.q new file mode 100644 index 0000000000..47ac526152 --- /dev/null +++ ql/src/test/queries/clientpositive/orc_avro_partition_uniontype.q @@ -0,0 +1,9 @@ +SET hive.exec.schema.evolution = false; + +CREATE TABLE avro_orc_partitioned_uniontype (a uniontype) PARTITIONED BY (b int) STORED AS ORC; + +INSERT INTO avro_orc_partitioned_uniontype PARTITION (b=1) SELECT create_union(1, true, value) FROM src LIMIT 5; + +ALTER TABLE avro_orc_partitioned_uniontype SET FILEFORMAT AVRO; + +SELECT * FROM avro_orc_partitioned_uniontype; diff --git ql/src/test/results/clientpositive/orc_avro_partition_uniontype.q.out ql/src/test/results/clientpositive/orc_avro_partition_uniontype.q.out new file mode 100644 index 0000000000..da8d9cc356 --- /dev/null +++ ql/src/test/results/clientpositive/orc_avro_partition_uniontype.q.out @@ -0,0 +1,40 @@ +PREHOOK: query: CREATE TABLE avro_orc_partitioned_uniontype (a uniontype) PARTITIONED BY (b int) STORED AS ORC +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@avro_orc_partitioned_uniontype +POSTHOOK: query: CREATE TABLE avro_orc_partitioned_uniontype (a uniontype) PARTITIONED BY (b int) STORED AS ORC +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@avro_orc_partitioned_uniontype +PREHOOK: query: INSERT INTO avro_orc_partitioned_uniontype PARTITION (b=1) SELECT create_union(1, true, value) FROM src LIMIT 5 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: default@avro_orc_partitioned_uniontype@b=1 +POSTHOOK: query: INSERT INTO avro_orc_partitioned_uniontype PARTITION (b=1) SELECT create_union(1, true, value) FROM src LIMIT 5 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +POSTHOOK: Output: default@avro_orc_partitioned_uniontype@b=1 +POSTHOOK: Lineage: avro_orc_partitioned_uniontype PARTITION(b=1).a EXPRESSION [(src)src.FieldSchema(name:value, type:string, comment:default), ] +PREHOOK: query: ALTER TABLE avro_orc_partitioned_uniontype SET FILEFORMAT AVRO +PREHOOK: type: ALTERTABLE_FILEFORMAT +PREHOOK: Input: default@avro_orc_partitioned_uniontype +PREHOOK: Output: default@avro_orc_partitioned_uniontype +POSTHOOK: query: ALTER TABLE avro_orc_partitioned_uniontype SET FILEFORMAT AVRO +POSTHOOK: type: ALTERTABLE_FILEFORMAT +POSTHOOK: Input: default@avro_orc_partitioned_uniontype +POSTHOOK: Output: default@avro_orc_partitioned_uniontype +PREHOOK: query: SELECT * FROM avro_orc_partitioned_uniontype +PREHOOK: type: QUERY +PREHOOK: Input: default@avro_orc_partitioned_uniontype +PREHOOK: Input: default@avro_orc_partitioned_uniontype@b=1 +#### A masked pattern was here #### +POSTHOOK: query: SELECT * FROM avro_orc_partitioned_uniontype +POSTHOOK: type: QUERY +POSTHOOK: Input: default@avro_orc_partitioned_uniontype +POSTHOOK: Input: default@avro_orc_partitioned_uniontype@b=1 +#### A masked pattern was here #### +{1:"val_165"} 1 +{1:"val_27"} 1 +{1:"val_311"} 1 +{1:"val_86"} 1 +{1:"val_238"} 1 diff --git serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorConverters.java serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorConverters.java index 7921de8d9c..35a6d21067 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorConverters.java +++ serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorConverters.java @@ -471,7 +471,7 @@ public Object convert(Object input) { } Object inputFieldValue = inputOI.getField(input); - Object inputFieldTag = inputOI.getTag(input); + byte inputFieldTag = inputOI.getTag(input); Object outputFieldValue = null; int inputFieldTagIndex = ((Byte)inputFieldTag).intValue(); @@ -480,7 +480,7 @@ public Object convert(Object input) { outputFieldValue = fieldConverters.get(inputFieldTagIndex).convert(inputFieldValue); } - outputOI.addField(output, outputFieldValue); + outputOI.addField(output, outputFieldValue, inputFieldTag); return output; } diff --git serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/SettableUnionObjectInspector.java serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/SettableUnionObjectInspector.java index 564d8d6045..3ac9d25f37 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/SettableUnionObjectInspector.java +++ serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/SettableUnionObjectInspector.java @@ -30,5 +30,5 @@ public abstract Object create(); /* Add field to the object */ - public abstract Object addField(Object union, Object field); + public abstract Object addField(Object union, Object field, byte tag); } diff --git serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardUnionObjectInspector.java serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardUnionObjectInspector.java index 7b2868233f..bece2046ea 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardUnionObjectInspector.java +++ serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardUnionObjectInspector.java @@ -144,15 +144,15 @@ public String toString() { @Override public Object create() { - ArrayList a = new ArrayList(); - return a; + return new StandardUnion(); } @Override - public Object addField(Object union, Object field) { - ArrayList a = (ArrayList) union; - a.add(field); - return a; + public Object addField(Object union, Object field, byte tag) { + StandardUnion unionObject = (StandardUnion) union; + unionObject.setObject(field); + unionObject.setTag(tag); + return unionObject; } }