[ 
https://issues.apache.org/jira/browse/IMPALA-7083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16775559#comment-16775559
 ] 

Paul Rogers commented on IMPALA-7083:
-------------------------------------

This issue turns out to be related to IMPALA-7753. The rewriter currently uses 
a four-step process:

* Analyze the tree and make copies of expressions, such as for the "sort info" 
structure.
* Rewrite selected expressions (such as the sort info structure)
* Throw away the analysis state (including the sort info structure)
* Re-analyze, making new copies of expressions (such as the sort-info structure)

The result is that we rewrite the copy of sort info, discard that copy, and 
revert to the original. We lose some semantic info in the process.

There is an ongoing effort to clean up the rewriter, to reduce the steps to:

* Analyze the tree, rewrite expressions and make copy of expressions

The work-in-progress branch with these changes resolves the issue here. 
However, the work requires quite a bit of change and we are slowly adding it 
one patch at a time.

> AnalysisException for GROUP BY and ORDER BY expressions that are folded to 
> constants from 2.9 onwards
> -----------------------------------------------------------------------------------------------------
>
>                 Key: IMPALA-7083
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7083
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>    Affects Versions: Impala 2.9.0
>            Reporter: Eric Lin
>            Priority: Critical
>              Labels: regression
>
> To reproduce, please run below impala query:
> {code}
> DROP TABLE IF EXISTS test;
> CREATE TABLE test (a int);
> SELECT   ( 
>     CASE 
>        WHEN (1 =1) 
>        THEN 1
>        ELSE a
>     end) AS b
> FROM  test 
> GROUP BY 1 
> ORDER BY ( 
>     CASE 
>        WHEN (1 =1) 
>        THEN 1
>        ELSE a
>     end);
> {code}
> It will fail with below error:
> {code}
> ERROR: AnalysisException: ORDER BY expression not produced by aggregation 
> output (missing from GROUP BY clause?): (CASE WHEN TRUE THEN 1 ELSE a END)
> {code}
> However, if I replace column name "a" as a constant value, it works:
> {code}
> SELECT   ( 
>     CASE 
>        WHEN (1 =1) 
>        THEN 1
>        ELSE 2
>     end) AS b
> FROM  test 
> GROUP BY 1 
> ORDER BY ( 
>     CASE 
>        WHEN (1 =1) 
>        THEN 1
>        ELSE 2
>     end);
> {code}
> This issue is identified in CDH5.12.x (Impala 2.9), and no issues in 5.11.x 
> (Impala 2.8).
> We know that it can be worked around by re-write as below:
> {code}
> SELECT   ( 
>     CASE 
>        WHEN (1 =1) 
>        THEN 1
>        ELSE a
>     end) AS b
> FROM  test 
> GROUP BY 1 
> ORDER BY 1;
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscr...@impala.apache.org
For additional commands, e-mail: issues-all-h...@impala.apache.org

Reply via email to