1fanwang opened a new pull request, #5225:
URL: https://github.com/apache/calcite/pull/5225

   ## Jira Link
   
   [CALCITE-7744](https://issues.apache.org/jira/browse/CALCITE-7744)
   
   ## Changes Proposed
   
   `SELECT max(sal) AS sal, deptno, job FROM emp GROUP BY deptno, job ORDER BY 
max(sal)` passes validation but fails during execution with `Unable to 
implement EnumerableCalc`.
   
   The ORDER BY alias expansion turns the expression into `max(max(sal))` after 
the original expression has already been validated. The inner aggregate then 
leaks into a `Project`. Validate expanded non-measure ORDER BY expressions 
before SQL-to-rel conversion. The query now returns Calcite's existing 
`Aggregate expressions cannot be nested` validation error instead of building 
an illegal plan. Measure aliases retain their existing scope and conversion 
path.
   
   ### Verification
   
   ```shell
   JAVA_HOME=$(/usr/libexec/java_home -v 21) ./gradlew :core:test \
     --tests org.apache.calcite.test.SqlValidatorTest \
     --tests org.apache.calcite.test.JdbcTest --no-daemon
   ```
   
   The JDBC regression uses `CalciteAssert.Config.SCOTT` and the query above. 
The same test ran against production source from `upstream/main` and from this 
branch.
   
   <details>
   <summary>Raw logs</summary>
   
   ```text
   Before:
   java.sql.SQLException: Unable to implement EnumerableCalc(...)
     EnumerableAggregate(group=[{0, 1}], SAL=[MAX($2)], agg#1=[MAX($3)])
       EnumerableCalc(... expr#8=[MAX($t5)] ...)
   Suppressed: java.lang.RuntimeException: cannot translate call MAX($t5)
   1 test completed, 1 failed
   
   After:
   SqlValidatorTest: 593 completed, 0 failed, 7 skipped
   JdbcTest: 409 completed, 0 failed, 17 skipped
   Gradle Test Run :core:test: 1002 completed, 0 failed, 24 skipped
   BUILD SUCCESSFUL
   ```
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to