yashmayya opened a new pull request, #20298: URL: https://github.com/apache/pinot/pull/20298
## Summary Follow-up to #20091. It has two fixes for the `preferSelectAliasInGroupBy` option. ### 1. The option broke queries that group by an alias that is not a column With the option set, every `GROUP BY` name that matched a `SELECT` alias became an ordinal. Calcite expands an alias, but not an ordinal, when the `SELECT` item uses another alias or a `USING` column. These queries work without the option and on Calcite 1.40, but they failed with the option: ```sql -- Column 'u' not found in any table SELECT UPPER(col1) AS u, LOWER(u) AS l, COUNT(*) FROM a GROUP BY u, l -- Column 'col1' is ambiguous SELECT UPPER(col1) AS u, COUNT(*) FROM a JOIN b USING (col1) GROUP BY u ``` Now only a name that is also exactly one column of the `FROM` clause becomes an ordinal. Both Calcite versions already resolve the other names to the alias. The check needs the scopes, so the rewrite moves from `performUnconditionalRewrites` to `validateGroupClause`. The meter and the exception do not change. ### 2. The controller `/sql` retry missed queries that fail after validation A query that resolves a `GROUP BY` name to the column can also fail after validation. For example, `HAVING col3 = 'late'` then compares an INT column with a string, and the optimizer fails with error 720. `QueryEnvironment.compile` now throws `GroupByAliasShadowedByColumnException` for a failure in any compile step, so the controller retries these queries too. ### Limit A name that a column shadows still becomes an ordinal. If its `SELECT` item uses another alias or a `USING` column, the query still fails with the option. ## Tests - `GroupByPlans.json`: with the option, a query that groups by an alias that is not a column and uses another alias gives the same plan as without it. - `PinotQueryResourceTest`: the controller retries a query that fails after validation. Both tests fail without the fix. `ResourceBasedQueryPlansTest`, `QueryCompilationTest`, `ResourceBasedQueriesTest`, `QueryRunnerTest`, `GroupByAliasShadowedByColumnMeterTest`, `GroupByAliasShadowedByColumnExceptionTest`, `PinotQueryResourceTest` and `MultiStageBrokerRequestHandlerTest` pass. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
