yonatan-sevenai commented on code in PR #21593:
URL: https://github.com/apache/datafusion/pull/21593#discussion_r3119150565
##########
datafusion/sql/src/unparser/ast.rs:
##########
@@ -162,9 +162,28 @@ pub struct SelectBuilder {
qualify: Option<ast::Expr>,
value_table_mode: Option<ast::ValueTableMode>,
flavor: Option<SelectFlavor>,
+ /// Counter for generating unique LATERAL FLATTEN aliases within this
SELECT.
+ flatten_alias_counter: usize,
}
impl SelectBuilder {
+ /// Generate a unique alias for a LATERAL FLATTEN relation
+ /// (`_unnest_1`, `_unnest_2`, …). Each call returns a fresh name.
+ pub fn next_flatten_alias(&mut self) -> String {
+ self.flatten_alias_counter += 1;
+ format!("_unnest_{}", self.flatten_alias_counter)
Review Comment:
Hi @goldmedal.
The query you suggested actually ends up emitting a single unnest node in DF
iterating over both arrays.
I did end up adding the test `snowflake_flatten_multiple_unnest_cross_join`
(in `plan_to_sql.rs`) which uses the following query, which also has the
benefit of simulating cartesian product. The two parallel `unnest`s aren't
actually possible in snowflake as each flatten is it's own iteration.
```sql
SELECT a.a, b.b FROM multi_array_table CROSS JOIN UNNEST(column_a) AS a (a)
CROSS JOIN UNNEST(column_b) AS b (b)`
```
which generates the following query
```sql
SELECT "a"."VALUE", "b"."VALUE" FROM "multi_array_table" CROSS JOIN LATERAL
FLATTEN(INPUT => "multi_array_table"."column_a") AS "a" CROSS JOIN LATERAL
FLATTEN(INPUT => "multi_array_table"."column_b") AS "b""
```
--
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]