IMPALA-4849: IllegalStateException from rewritten CASE expr In SelectList.reset(), we call reset() on each select list item's expr. reset() is supposed to remove implicit casts, by returning the reset expr with implicit cast exprs removed from the tree.
Previously SelectList.reset() ignored the return value of the calls to Expr.reset(), meaning that if the top-most expr of the select list item is an implicit cast, it won't actually get removed, which causes problems with analysis since implicit casts are always treated as pre-analyzed. The solution is to set the select list item's exprs to the return value of reset(). Testing: - Added a regression test to exprs.test Change-Id: I16ff88716b185e1d72d2bc603a42bd06c60ec18e Reviewed-on: http://gerrit.cloudera.org:8080/5917 Reviewed-by: Alex Behm <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/3edc9099 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/3edc9099 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/3edc9099 Branch: refs/heads/master Commit: 3edc9099bcd1b2e962c83575bbb38155b77b780e Parents: 87cec88 Author: Thomas Tauber-Marshall <[email protected]> Authored: Mon Feb 6 12:46:18 2017 -0800 Committer: Impala Public Jenkins <[email protected]> Committed: Thu Feb 9 20:36:22 2017 +0000 ---------------------------------------------------------------------- .../java/org/apache/impala/analysis/SelectList.java | 2 +- .../functional-query/queries/QueryTest/exprs.test | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/3edc9099/fe/src/main/java/org/apache/impala/analysis/SelectList.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/org/apache/impala/analysis/SelectList.java b/fe/src/main/java/org/apache/impala/analysis/SelectList.java index d7f12ff..1e7780e 100644 --- a/fe/src/main/java/org/apache/impala/analysis/SelectList.java +++ b/fe/src/main/java/org/apache/impala/analysis/SelectList.java @@ -103,7 +103,7 @@ public class SelectList { public void reset() { for (SelectListItem item: items_) { - if (!item.isStar()) item.getExpr().reset(); + if (!item.isStar()) item.setExpr(item.getExpr().reset()); } } } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/3edc9099/testdata/workloads/functional-query/queries/QueryTest/exprs.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/exprs.test b/testdata/workloads/functional-query/queries/QueryTest/exprs.test index 3b2383e..d611884 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/exprs.test +++ b/testdata/workloads/functional-query/queries/QueryTest/exprs.test @@ -2692,3 +2692,18 @@ where id = case when false then 0 when 1 = 1 then 1 else 2 end ---- TYPES INT,TINYINT ==== +---- QUERY +# IMPALA-4849: verify that DISTINCT with a CASE that is rewritten analyzes correctly. +select distinct case when true then id else 0 end from functional.alltypestiny +---- RESULTS +0 +1 +2 +3 +4 +5 +6 +7 +---- TYPES +INT +==== \ No newline at end of file
