yonatan-sevenai commented on code in PR #21593:
URL: https://github.com/apache/datafusion/pull/21593#discussion_r3087890416


##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -211,6 +206,15 @@ pub trait Dialect: Send + Sync {
         false
     }
 
+    /// Unparse the unnest plan as `LATERAL FLATTEN(INPUT => expr, ...)`.
+    ///
+    /// Snowflake uses FLATTEN as a table function instead of the SQL-standard 
UNNEST.
+    /// When this returns `true`, the unparser emits
+    /// `LATERAL FLATTEN(INPUT => <col>, OUTER => <bool>)` in the FROM clause.
+    fn unnest_as_lateral_flatten(&self) -> bool {
+        false
+    }

Review Comment:
   Hmm...
   So far, all the dialect specific changes I've seen in dialects really focus 
on very minor syntactic generation (for example the 
`scalar_function_to_sql_override` and the `timestamp_with_tz_to_string`).
   
   In contrast we've had to add a new AST node `FlattenRelationBuilder` in 
`ast.rs` which is a rather involved structural node (support for `CROSS JOIN`s 
and the various `OUTER=` syntaxes needed). I'm not sure it's a good idea to put 
these inside the dialect. 
   
   Outside, we added various utils (such as 
`unproject_unnest_expr_as_flatten_value` in `utils.rs`).
   The big changes in this PR (other than tons of tests in `plan_to_sql.rs` is 
focused on the `plan.rs` file.
   
   90% of the logic there if focused on untangling all the ways an Unnest node 
can interact with other entities (UDFs, `SubqueryAlias`, `Projection`, 
`Limits`, `Sorts`) etc. 
   I've seen some weird shapes come out of the optimizer that I wanted to 
ensure get supported. This traversal logic is very consistent with the way the 
Unparser works across the board now.
   
   In other words, the Snowflake specific items are mostly business logic in 
how to really decompose the unnest forms supported in DF vs the completely 
different forms in takes in Snowflake. 
   
   We could move the AST `FlattenRelationBuilder` inside the dialect, but I 
feel this breaks the current separation strategy in DF's design.



-- 
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]

Reply via email to