yonatan-sevenai commented on code in PR #21593:
URL: https://github.com/apache/datafusion/pull/21593#discussion_r3101832311
##########
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:
I implemented all the changes mentioned below except moving the
`FlattenRelationBuilder` inside the dialect.
I'd love to get the idea of dialect specific hooks implemented, but I'm not
sure what's the best way to get there.
We can easily move the `FlattenRelationBuilder` into the dialect, but it's
currently created in `try_unnest_to_lateral_flatten_sql` which does structural
traversal and then used again in `try_projection_unnest_as_lateral_flatten`,
both do structural traversal and unpeeling of the plan so they still belong to
`plan.rs`.
Therefore, if we simply move the `FlattenRelationBuilder` we either have a
dialect generic method that returns a `Box<dyn RelationBuilder>` or hard code
the pairing into `SnowflakeDialect::FlattenRelationBuilder`.
Neither of those feel attractive to me.
A long term option to really think if there's a more generic way to do
dialect specific transforms, and bring *both* the structural analysis (plan
traversal, unpeeling, etc) and AST builder into the dialects, but I feel this
is a pretty invasive change with a large blast radius that I don't want to bind
into this PR. Consider, for example, how BQ handles `UNNEST` is also not
entirely similar to how Postgres (for example) handles `UNNEST`s
--
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]