You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Zine eddine Zidane (Jira)" <ji...@apache.org> on 2023/03/21 11:06:00 UTC

[jira] [Created] (CALCITE-5598) Expand expression in a GROUP BY clause returns wrong result in case of expressions referenced by column index

Zine eddine Zidane created CALCITE-5598:
-------------------------------------------

             Summary: Expand expression in a GROUP BY clause returns wrong result in case of expressions referenced by column index
                 Key: CALCITE-5598
                 URL: https://issues.apache.org/jira/browse/CALCITE-5598
             Project: Calcite
          Issue Type: Bug
    Affects Versions: 1.34.0
            Reporter: Zine eddine Zidane


Given the following BigQuery query:

 
{code:java}
SELECT CAST(user_id AS STRING) AS id, COUNT(*) FROM `users` GROUP BY 1 HAVING COUNT (*)>1;{code}
 

SqlValidatorImpl extendedExpand method returns "CAST(user_id AS STRING)" for expression “1” in the GROUP BY clause resulting in the following validated query:

 
{code:java}
SELECT CAST(user_id AS STRING) AS id, COUNT(*) FROM `users` GROUP BY CAST(user_id AS STRING) HAVING COUNT (*)>1;{code}
 

This query fails on BigQuery with the error: 
{code:java}
SELECT list expression references user_id which is neither grouped nor aggregated at [1:24] on source.{code}



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