Hey Jacobo,

This indeed seems like a bug in Impala's query rewriting logic, and it
is also present on the current master branch.
Please feel free to file a Jira ticket for this.

Though I'm also curious about the use case of having constant
predicates in the WHEN clause (e.g. -1 < 0).
In the meantime, as a workaround maybe you could use ordinals in the
GROUP BY, e.g.:

SELECT CASE WHEN -1 < 0 THEN t0.<field name> ELSE 'X' END
FROM <table name> t0
GROUP BY 1;

Best regards,
    Zoltan

On Mon, Oct 14, 2024 at 1:13 PM Jacobo Sánchez López
<jsanc...@denodo.com> wrote:
>
>
>
> Hi
>
>    I am analyzing some query errors from projection expressions not matching 
> grouping: "select list expression not produced by aggregation output"
>
>    Doing some simplified test queries I ended up in a scenario where I don't 
> see if the results are expected or a limitation/bug on Impala.
>
> This works:
>
> 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;
>
> However this one where the results come from the field  do not work:
>
> 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;
>
> This one works:
>
> SELECT CASE WHEN t0.<field name> = 'b' THEN 'found' ELSE t0.<field name> END
>
> FROM <table name> t0
>
> GROUP BY WHEN t0.<field name> = 'b' THEN 'found' ELSE t0.<field name> END;
>
> However not using the field reference does not work (even if the result is 
> the same):
>
> SELECT CASE WHEN 'a' = 'b' THEN 'found' ELSE t0.summary END
>
> FROM <table name> t0
>
> GROUP BY CASE WHEN 'a' = 'b' THEN 'found' ELSE t0.summary END;
>
>
>     I could only find this JIRA as somehow related but it is from 2015 
> https://issues.apache.org/jira/browse/DRILL-1927 (Aggregation or Group-By on 
> a CASE expression with IN subquery fails)
>
>     Any one knows if this is somehow expected, limitation or bug? I have 
> tested this on 3.4.0 version
>
>
> Best regards,
>
> Jacobo Sánchez

Reply via email to