This is an automated email from the ASF dual-hosted git repository. kgyrtkirk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push: new 69331f2 HIVE-24902: Incorrect result after fold CASE into COALESCE (#2100) (Nemon Lou reviewed by Zoltan Haindrich) 69331f2 is described below commit 69331f2a26da639c6c011adc1bac8ce3b054fa8c Author: loudongfeng <nemon...@qq.com> AuthorDate: Fri Aug 6 21:23:19 2021 +0800 HIVE-24902: Incorrect result after fold CASE into COALESCE (#2100) (Nemon Lou reviewed by Zoltan Haindrich) --- .../ql/parse/type/ExprNodeDescExprFactory.java | 3 +- .../clientpositive/constant_prop_coalesce.q | 30 +++++++ .../llap/constant_prop_coalesce.q.out | 95 ++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/type/ExprNodeDescExprFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/type/ExprNodeDescExprFactory.java index aad2cfe..a5e6ad5 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/type/ExprNodeDescExprFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/type/ExprNodeDescExprFactory.java @@ -809,7 +809,8 @@ public class ExprNodeDescExprFactory extends ExprFactory<ExprNodeDesc> { Object thenVal = constThen.getValue(); Object elseVal = constElse.getValue(); if (thenVal instanceof Boolean && elseVal instanceof Boolean) { - return true; + //only convert to COALESCE when both branches are valid + return !thenVal.equals(elseVal); } } return false; diff --git a/ql/src/test/queries/clientpositive/constant_prop_coalesce.q b/ql/src/test/queries/clientpositive/constant_prop_coalesce.q new file mode 100644 index 0000000..f81b4b9 --- /dev/null +++ b/ql/src/test/queries/clientpositive/constant_prop_coalesce.q @@ -0,0 +1,30 @@ +explain +select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null; + +select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null; \ No newline at end of file diff --git a/ql/src/test/results/clientpositive/llap/constant_prop_coalesce.q.out b/ql/src/test/results/clientpositive/llap/constant_prop_coalesce.q.out new file mode 100644 index 0000000..d34fcb6 --- /dev/null +++ b/ql/src/test/results/clientpositive/llap/constant_prop_coalesce.q.out @@ -0,0 +1,95 @@ +PREHOOK: query: explain +select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: explain +select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +STAGE DEPENDENCIES: + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-0 + Fetch Operator + limit: -1 + Processor Tree: + TableScan + alias: _dummy_table + Row Limit Per Split: 1 + Select Operator + expressions: 2 (type: int), 1 (type: int), 2 (type: int) + outputColumnNames: _col0, _col1, _col2 + UDTF Operator + function name: stack + Filter Operator + predicate: CASE WHEN ((col0 = 1)) THEN (true) ELSE (true) END (type: boolean) + Select Operator + expressions: CASE WHEN ((col0 = 1)) THEN (20210308L) ELSE (20210309L) END (type: bigint) + outputColumnNames: _col0 + ListSink + +PREHOOK: query: select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: select * from ( +select + case when b.a=1 + then + cast (from_unixtime(unix_timestamp(cast(20210309 as string),'yyyyMMdd') - 86400,'yyyyMMdd') as bigint) + else + 20210309 + end +as col +from +(select stack(2,1,2) as (a)) + as b +) t +where t.col is not null +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +20210308 +20210309