goldmedal commented on code in PR #12994:
URL: https://github.com/apache/datafusion/pull/12994#discussion_r1806676727
##########
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:
I found the test only covers the `derived_sort` case but some cases aren't
covered, such as `derived_projection`, `derived_limit`,...
Could you add more tests for them?
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -239,6 +244,22 @@ impl Unparser<'_> {
Ok(())
}
+ fn derive_with_dialect_alias(
+ &self,
+ alias: &str,
+ plan: &LogicalPlan,
+ relation: &mut RelationBuilder,
+ ) -> Result<()> {
+ match self.dialect.requires_derived_table_alias() {
+ false => self.derive(plan, relation, None),
+ true => self.derive(
+ plan,
+ relation,
+ Some(self.new_table_alias(alias.to_string(), vec![])),
+ ),
+ }
Review Comment:
Using `if-else` clause would be clear
```suggestion
if self.dialect.requires_derived_table_alias() {
self.derive(
plan,
relation,
Some(self.new_table_alias(alias.to_string(), vec![])),
)
} else {
self.derive(plan, relation, None)
}
```
--
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]