aleksandar-trajkovic-db opened a new pull request, #60235: URL: https://github.com/apache/spark/pull/60235
### What changes were proposed in this pull request? Add `JdbcDialect.supportsTopN(orders, aggregation)`, consulted by `JDBCScanBuilder.pushTopN`. `MySQLDialect` refuses the sort keys MySQL's `ONLY_FULL_GROUP_BY` rejects; the aggregate stays pushed and Spark sorts and limits locally. The internal conf `spark.sql.legacy.mysql.topNOverGroupByExpr.enabled` restores the old pushdown. ### Why are the changes needed? 1. Goal: `ORDER BY ... LIMIT` over a pushed GROUP BY expression succeeds on MySQL. 2. Problem: TopN sort keys are rewritten to the GROUP BY expressions, and MySQL's default `ONLY_FULL_GROUP_BY` rejects a term built over one: ```sql SELECT k + 1, COUNT(*) FROM mysql.db.t GROUP BY k + 1 ORDER BY (k + 1) * 2 LIMIT 10 ``` ``` Before: SELECT `k` + 1,COUNT(*) FROM `db`.`t` GROUP BY `k` + 1 ORDER BY (`k` + 1) * 2 ASC LIMIT 10 -> MySQL error 1055 Target: SELECT `k` + 1,COUNT(*) FROM `db`.`t` GROUP BY `k` + 1 (ORDER BY ... LIMIT runs in Spark) ``` ### Does this PR introduce _any_ user-facing change? Yes. Such queries now succeed instead of failing with `JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR`; sort keys MySQL accepts (e.g. `ORDER BY k + 1`, `ORDER BY COUNT(*)`) are still pushed. ### How was this patch tested? New tests in `MySQLIntegrationSuite`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Isaac) with Claude Opus 5.5 This pull request and its description were written by Isaac. -- 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]
