diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index b323ede..14b124e 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -10186,6 +10186,7 @@ private Operator genUnionPlan(String unionalias, String leftalias, parent.add(rightOp); UnionDesc uDesc = ((UnionOperator) leftOp).getConf(); + leftOp.setSchema(new RowSchema(unionoutRR.getColumnInfos())); uDesc.setNumInputs(uDesc.getNumInputs() + 1); return putOpInsertMap(leftOp, unionoutRR); } @@ -10213,6 +10214,7 @@ private Operator genUnionPlan(String unionalias, String leftalias, .getParentOperators(); parent.add(leftOp); UnionDesc uDesc = ((UnionOperator) rightOp).getConf(); + rightOp.setSchema(new RowSchema(unionoutRR.getColumnInfos())); uDesc.setNumInputs(uDesc.getNumInputs() + 1); return putOpInsertMap(rightOp, unionoutRR); diff --git ql/src/test/queries/clientpositive/union_different_types_three.q ql/src/test/queries/clientpositive/union_different_types_three.q new file mode 100644 index 0000000..6f80533 --- /dev/null +++ ql/src/test/queries/clientpositive/union_different_types_three.q @@ -0,0 +1,40 @@ +create table test_union_different_type(id bigint, id2 bigint, id3 bigint, name string); +set hive.cbo.enable=false; +set hive.auto.convert.join; +set hive.auto.convert.join=true; +insert overwrite table test_union_different_type select 1, 2, 3, "test_union_different_type"; +--create table test_desc_table_haihua_2 as +explain select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +; +select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +; + +drop table test_union_different_type; diff --git ql/src/test/results/clientpositive/union_different_types_three.q.out ql/src/test/results/clientpositive/union_different_types_three.q.out new file mode 100644 index 0000000..4271d0c --- /dev/null +++ ql/src/test/results/clientpositive/union_different_types_three.q.out @@ -0,0 +1,195 @@ +PREHOOK: query: create table test_union_different_type(id bigint, id2 bigint, id3 bigint, name string) +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@test_union_different_type +POSTHOOK: query: create table test_union_different_type(id bigint, id2 bigint, id3 bigint, name string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@test_union_different_type +hive.auto.convert.join=false +PREHOOK: query: insert overwrite table test_union_different_type select 1, 2, 3, "test_union_different_type" +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +PREHOOK: Output: default@test_union_different_type +POSTHOOK: query: insert overwrite table test_union_different_type select 1, 2, 3, "test_union_different_type" +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +POSTHOOK: Output: default@test_union_different_type +POSTHOOK: Lineage: test_union_different_type.id EXPRESSION [] +POSTHOOK: Lineage: test_union_different_type.id2 EXPRESSION [] +POSTHOOK: Lineage: test_union_different_type.id3 EXPRESSION [] +POSTHOOK: Lineage: test_union_different_type.name SIMPLE [] +PREHOOK: query: explain select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +PREHOOK: type: QUERY +POSTHOOK: query: explain select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +POSTHOOK: type: QUERY +STAGE DEPENDENCIES: + Stage-6 is a root stage + Stage-5 depends on stages: Stage-6 + Stage-0 depends on stages: Stage-5 + +STAGE PLANS: + Stage: Stage-6 + Map Reduce Local Work + Alias -> Map Local Tables: + t01-subquery1-subquery1:_u1-subquery1-subquery1:test_union_different_type + Fetch Operator + limit: -1 + t01-subquery1-subquery2:_u1-subquery1-subquery2:test_union_different_type + Fetch Operator + limit: -1 + t01-subquery2:_u1-subquery2:test_union_different_type + Fetch Operator + limit: -1 + Alias -> Map Local Operator Tree: + t01-subquery1-subquery1:_u1-subquery1-subquery1:test_union_different_type + TableScan + alias: test_union_different_type + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: 1 (type: int), 30 (type: int), id3 (type: bigint) + outputColumnNames: _col0, _col1, _col2 + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Union + Statistics: Num rows: 3 Data size: 93 Basic stats: COMPLETE Column stats: NONE + HashTable Sink Operator + keys: + 0 id (type: bigint) + 1 _col0 (type: bigint) + t01-subquery1-subquery2:_u1-subquery1-subquery2:test_union_different_type + TableScan + alias: test_union_different_type + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: 2 (type: int), 20 (type: int), id3 (type: bigint) + outputColumnNames: _col0, _col1, _col2 + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Union + Statistics: Num rows: 3 Data size: 93 Basic stats: COMPLETE Column stats: NONE + HashTable Sink Operator + keys: + 0 id (type: bigint) + 1 _col0 (type: bigint) + t01-subquery2:_u1-subquery2:test_union_different_type + TableScan + alias: test_union_different_type + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: id (type: bigint), id2 (type: bigint), 30 (type: bigint) + outputColumnNames: _col0, _col1, _col2 + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Union + Statistics: Num rows: 3 Data size: 93 Basic stats: COMPLETE Column stats: NONE + HashTable Sink Operator + keys: + 0 id (type: bigint) + 1 _col0 (type: bigint) + + Stage: Stage-5 + Map Reduce + Map Operator Tree: + TableScan + alias: t00 + Statistics: Num rows: 1 Data size: 31 Basic stats: COMPLETE Column stats: NONE + Map Join Operator + condition map: + Left Outer Join 0 to 1 + keys: + 0 id (type: bigint) + 1 _col0 (type: bigint) + outputColumnNames: _col0, _col7, _col8, _col9 + Statistics: Num rows: 3 Data size: 102 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: _col7 (type: bigint), _col8 (type: bigint), _col0 (type: bigint), _col9 (type: bigint) + outputColumnNames: _col0, _col1, _col2, _col3 + Statistics: Num rows: 3 Data size: 102 Basic stats: COMPLETE Column stats: NONE + File Output Operator + compressed: false + Statistics: Num rows: 3 Data size: 102 Basic stats: COMPLETE Column stats: NONE + table: + input format: org.apache.hadoop.mapred.SequenceFileInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + Local Work: + Map Reduce Local Work + + Stage: Stage-0 + Fetch Operator + limit: -1 + Processor Tree: + ListSink + +PREHOOK: query: select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +PREHOOK: type: QUERY +PREHOOK: Input: default@test_union_different_type +#### A masked pattern was here #### +POSTHOOK: query: select + t01.diff_long_type as diff_long_type, + t01.id2 as id2, + t00.id as id, + t01.id3 as id3 +from test_union_different_type t00 +left join + ( + select 1 as diff_long_type, 30 as id2, id3 from test_union_different_type + union ALL + select 2 as diff_long_type, 20 as id2, id3 from test_union_different_type + union ALL + select id as diff_long_type, id2, 30 as id3 from test_union_different_type + ) t01 +on t00.id = t01.diff_long_type +POSTHOOK: type: QUERY +POSTHOOK: Input: default@test_union_different_type +#### A masked pattern was here #### +1 2 1 30 +1 30 1 3 +PREHOOK: query: drop table test_union_different_type +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@test_union_different_type +PREHOOK: Output: default@test_union_different_type +POSTHOOK: query: drop table test_union_different_type +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@test_union_different_type +POSTHOOK: Output: default@test_union_different_type