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)

Reply via email to