You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "Jacobo Sanchez (Jira)" <ji...@apache.org> on 2024/10/15 09:15:00 UTC

[jira] [Updated] (IMPALA-13447) GROUP BY using CASE expression with literals at the WHEN clause fails

     [ https://issues.apache.org/jira/browse/IMPALA-13447?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacobo Sanchez updated IMPALA-13447:
------------------------------------
    Description: 
Impala throws an error when executing a group by having the same expression at projection and group by. The requirements are grouping by a CASE statement with an directly evaluable expression in the WHEN clause and a field reference in the chosen branch

The error points to the query having different expressions: _select list expression not produced by aggregation output_
 * Using any table execute the following replacing <field name> and <table name>:

{code:sql}
SELECT CASE WHEN -1 > 0 THEN t0.<field name> ELSE 'X' END
FROM <table name> t0
GROUP BY CASE WHEN -1 > 0 THEN t0.<field name> ELSE 'X' END;
{code}
 This is working as WHEN is false and 'X' is printed at the output
 * Changing the WHEN condition to make the CASE evaluate the THEN instead of ELSE

{code:sql}
SELECT CASE WHEN -1 < 0 THEN t0.<field name> ELSE 'X' END
FROM <table name> t0
GROUP BY CASE WHEN -1 < 0 THEN t0.<field name> ELSE 'X' END;
{code}
{color:#172b4d}          This fails like if the projected and grouped expressions were not the same.{color}

{color:#172b4d}           Using any field reference at the WHEN clause does also make the query to work. My guess is that internally the CASE expression is being evaluated to the resulting branch value but only in one of the clauses{color}

 

 

 

  was:
Impala throws an error when executing a group by having the same expression at projection and group by. The requirements are grouping by a CASE statement with an directly evaluable expression in the WHEN clause and a field reference in the chosen branch

The error points to the query having different expressions: _select list expression not produced by aggregation output_

 
 * Using any table execute the following replacing <field name> and <table name>:

{color:#800000}SELECT{color} {color:#800000}CASE{color} {color:#800000}WHEN{color} -{color:#0000ff}1{color} > {color:#0000ff}0{color} {color:#800000}THEN{color} {color:#8e00c6}t0{color}.{color:#006464}<field name> {color}{color:#800000}ELSE{color} {color:#008000}'X'{color} {color:#800000}END{color}

{color:#800000}FROM{color} <table name> {color:#8e00c6}t0{color}

{color:#800000}GROUP{color} {color:#800000}BY{color} {color:#800000}CASE{color} {color:#800000}WHEN{color} -{color:#0000ff}1{color} > {color:#0000ff}0{color} {color:#800000}THEN{color} {color:#000000}t0{color}.<field name> {color:#800000}ELSE{color} {color:#008000}'X'{color} {color:#800000}END{color}{color:#ff0000};{color}

           __           This is working as WHEN is false and 'X' is printed at the output
 * Changing the WHEN condition to make the CASE evaluate the THEN instead of ELSE

{color:#800000}SELECT{color} {color:#800000}CASE{color} {color:#800000}WHEN{color} -{color:#0000ff}1{color} < {color:#0000ff}0{color} {color:#800000}THEN{color} {color:#8e00c6}t0{color}.{color:#006464}<field name> {color}{color:#800000}ELSE{color} {color:#008000}'X'{color} {color:#800000}END{color}

{color:#800000}FROM{color} <table name> {color:#8e00c6}t0{color}

{color:#800000}GROUP{color} {color:#800000}BY{color} {color:#800000}CASE{color} {color:#800000}WHEN{color} -{color:#0000ff}1{color} < {color:#0000ff}0{color} {color:#800000}THEN{color} {color:#000000}t0{color}.<field name> {color:#800000}ELSE{color} {color:#008000}'X'{color} {color:#800000}END{color}{color:#ff0000};{color}

 

{color:#172b4d}          This fails like if the projected and grouped expressions were not the same.{color}

 

{color:#172b4d}           Using any field reference at the WHEN clause does also make the query to work. My guess is that internally the CASE expression is being evaluated to the resulting branch value but only in one of the clauses{color}

 

 

 


> GROUP BY using CASE expression with literals at the WHEN clause fails
> ---------------------------------------------------------------------
>
>                 Key: IMPALA-13447
>                 URL: https://issues.apache.org/jira/browse/IMPALA-13447
>             Project: IMPALA
>          Issue Type: Bug
>    Affects Versions: Impala 3.4.0
>            Reporter: Jacobo Sanchez
>            Priority: Minor
>
> Impala throws an error when executing a group by having the same expression at projection and group by. The requirements are grouping by a CASE statement with an directly evaluable expression in the WHEN clause and a field reference in the chosen branch
> The error points to the query having different expressions: _select list expression not produced by aggregation output_
>  * Using any table execute the following replacing <field name> and <table name>:
> {code:sql}
> SELECT CASE WHEN -1 > 0 THEN t0.<field name> ELSE 'X' END
> FROM <table name> t0
> GROUP BY CASE WHEN -1 > 0 THEN t0.<field name> ELSE 'X' END;
> {code}
>  This is working as WHEN is false and 'X' is printed at the output
>  * Changing the WHEN condition to make the CASE evaluate the THEN instead of ELSE
> {code:sql}
> SELECT CASE WHEN -1 < 0 THEN t0.<field name> ELSE 'X' END
> FROM <table name> t0
> GROUP BY CASE WHEN -1 < 0 THEN t0.<field name> ELSE 'X' END;
> {code}
> {color:#172b4d}          This fails like if the projected and grouped expressions were not the same.{color}
> {color:#172b4d}           Using any field reference at the WHEN clause does also make the query to work. My guess is that internally the CASE expression is being evaluated to the resulting branch value but only in one of the clauses{color}
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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