HIVE-11919: Hive Union Type Mismatch (Laljo John Pullokkaran, reviewed by Jesus Camacho Rodriguez)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/768db673 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/768db673 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/768db673 Branch: refs/heads/llap Commit: 768db6732031a3a41cee9996a1021621ce244100 Parents: 7f9023e Author: jpullokk <[email protected]> Authored: Wed Oct 7 21:12:51 2015 -0700 Committer: jpullokk <[email protected]> Committed: Wed Oct 7 21:12:51 2015 -0700 ---------------------------------------------------------------------- .../apache/hadoop/hive/ql/exec/ColumnInfo.java | 2 +- .../hadoop/hive/ql/parse/CalcitePlanner.java | 3 +-- .../hadoop/hive/ql/parse/SemanticAnalyzer.java | 3 +-- .../hive/ql/udf/generic/GenericUDFUtils.java | 3 +-- ql/src/test/queries/clientpositive/union36.q | 10 +++++++ .../test/results/clientpositive/union36.q.out | 28 ++++++++++++++++++++ 6 files changed, 42 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java index 12bb1d7..e3da7f0 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/ColumnInfo.java @@ -107,7 +107,6 @@ public class ColumnInfo implements Serializable { this.isVirtualCol = columnInfo.getIsVirtualCol(); this.isHiddenVirtualCol = columnInfo.isHiddenVirtualCol(); this.setType(columnInfo.getType()); - this.typeName = columnInfo.getType().getTypeName(); } public String getTypeName() { @@ -133,6 +132,7 @@ public class ColumnInfo implements Serializable { public void setType(TypeInfo type) { objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(type); + setTypeName(type.getTypeName()); } public void setInternalName(String internalName) { http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java index 9c731b8..e68b385 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java @@ -1124,8 +1124,7 @@ public class CalcitePlanner extends SemanticAnalyzer { + " on second table")); } ColumnInfo unionColInfo = new ColumnInfo(lInfo); - unionColInfo.setType(FunctionRegistry.getCommonClassForUnionAll(lInfo.getType(), - rInfo.getType())); + unionColInfo.setType(commonTypeInfo); unionoutRR.put(unionalias, field, unionColInfo); } http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 7a54aec..a114281 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -9026,8 +9026,7 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer { + " on second table")); } ColumnInfo unionColInfo = new ColumnInfo(lInfo); - unionColInfo.setType(FunctionRegistry.getCommonClassForUnionAll(lInfo.getType(), - rInfo.getType())); + unionColInfo.setType(commonTypeInfo); unionoutRR.put(unionalias, field, unionColInfo); } http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java index 222e0e0..3bbe783 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java @@ -159,8 +159,7 @@ public final class GenericUDFUtils { // a common base class or not. TypeInfo commonTypeInfo = null; if (isUnionAll) { - commonTypeInfo = FunctionRegistry.getCommonClassForUnionAll(oiTypeInfo, - rTypeInfo); + commonTypeInfo = FunctionRegistry.getCommonClassForUnionAll(rTypeInfo, oiTypeInfo); } else { commonTypeInfo = FunctionRegistry.getCommonClass(oiTypeInfo, rTypeInfo); http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/test/queries/clientpositive/union36.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/union36.q b/ql/src/test/queries/clientpositive/union36.q new file mode 100644 index 0000000..e929749 --- /dev/null +++ b/ql/src/test/queries/clientpositive/union36.q @@ -0,0 +1,10 @@ +set hive.cbo.enable=false; + +select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y; + +select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y; + + + + + http://git-wip-us.apache.org/repos/asf/hive/blob/768db673/ql/src/test/results/clientpositive/union36.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/union36.q.out b/ql/src/test/results/clientpositive/union36.q.out new file mode 100644 index 0000000..12f060b --- /dev/null +++ b/ql/src/test/results/clientpositive/union36.q.out @@ -0,0 +1,28 @@ +PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y +PREHOOK: type: QUERY +PREHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select '100000000' x from (select * from src limit 2) s3)u order by y +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +#### A masked pattern was here #### +4.999999900000002E-9 +4.999999900000002E-9 +4.999999900000002E-9 +4.999999900000002E-9 +0.4999999900000002 +0.4999999900000002 +PREHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y +PREHOOK: type: QUERY +PREHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: query: select (x/sum(x) over()) as y from(select cast(1 as decimal(10,0)) as x from (select * from src limit 2)s1 union all select cast(1 as decimal(10,0)) x from (select * from src limit 2) s2 union all select cast (null as string) x from (select * from src limit 2) s3)u order by y +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +#### A masked pattern was here #### +NULL +NULL +0.25 +0.25 +0.25 +0.25
