Jacobo Sanchez created IMPALA-13447:
---------------------------------------
Summary: 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
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}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)