goldmedal commented on code in PR #12994:
URL: https://github.com/apache/datafusion/pull/12994#discussion_r1807260135
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
@@ -261,6 +261,24 @@ fn roundtrip_statement_with_dialect() -> Result<()> {
unparser_dialect: Box<dyn UnparserDialect>,
}
let tests: Vec<TestStatementWithDialect> = vec![
+ TestStatementWithDialect {
+ sql: "select min(ta.j1_id) as j1_min from j1 ta order by
min(ta.j1_id) limit 10;",
+ expected:
+ // top projection sort gets derived into a subquery
+ // for MySQL, this subquery needs an alias
+ "SELECT `j1_min` FROM (SELECT min(`ta`.`j1_id`) AS `j1_min`,
min(`ta`.`j1_id`) FROM `j1` AS `ta` ORDER BY min(`ta`.`j1_id`) ASC) AS
`derived_sort` LIMIT 10",
Review Comment:
For `derived_projection`, I found the SQL can trigger:
```sql
select j1_id from (select 1 as j1_id)
-> SELECT `j1_id` FROM (SELECT 1 AS `j1_id`) AS `derived_projection`
```
However, I guess it's not a valid SQL for MySQL, right? I tried it in
DataFusion and DuckDB, they accept it but Postgres doesn't allow it. Maybe, it
could be a `DataFusion` dialect to `MySQL` dialect case.
For `derived_limit`, a similar case can trigger it:
```sql
select * from (select * from j1 limit 10)
-> SELECT * FROM (SELECT * FROM `j1` LIMIT 10) AS `derived_limit`
```
--
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]