Conversation
|
Interestingly, I was working on a very similar PR last night: |
|
yes, @alamb, I think we got on the same issue with |
Yes, indeed -- something is going on with unnest. It would be great if you wanted to take over Feel free to pull over the test case from https://github.com/apache/datafusion/pull/15008/files as well |
|
|
||
| unnest_relation.alias(Some(self.new_table_alias(alias.to_string(), vec![]))); | ||
|
|
There was a problem hiding this comment.
@goldmedal FYI, this is another change to unnest - I want to always do alias to make behaviour more consistent
There was a problem hiding this comment.
I don't get why this way can make behavior more consistent 🤔. Could you explain more?
There was a problem hiding this comment.
BTW, I'm considering how to fix the issue mentioned in (#15090 (comment)). I think add an alias for the unnest may be a good idea.
I think it should like
| unnest_relation.alias(Some(self.new_table_alias(alias.to_string(), vec![]))); | |
| unnest_relation.alias(Some(self.new_table_alias("unnset_table_1", vec![alias.to_string()]))); |
Then, we can get the result like
SELECT "UNNEST(make_array(Int64(1),Int64(2),Int64(3)))" FROM UNNEST([1, 2, 3]) AS unnest_table ("UNNEST(make_array(Int64(1),Int64(2),Int64(3)))")It can not only fit what you want to do but generate a valid SQL. WDYT?
There was a problem hiding this comment.
I think this is an edge case example
SELECT * from UNNEST([1,2,3]), UNNEST([1,2,3,4])is transformed into
SELECT UNNEST(make_array(Int64(1),Int64(2),Int64(3))), UNNEST(make_array(Int64(1),Int64(2),Int64(3),Int64(4))) FROM UNNEST([1, 2, 3]) AS unnset_table_1 (UNNEST(make_array(Int64(1),Int64(2),Int64(3)))) CROSS JOIN UNNEST([1, 2, 3, 4]) AS unnset_table_1 (UNNEST(make_array(Int64(1),Int64(2),Int64(3),Int64(4))))# Conflicts: # datafusion/expr/src/expr.rs # datafusion/sql/src/unparser/plan.rs # datafusion/sql/tests/cases/plan_to_sql.rs
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Which issue does this PR close?
Rationale for this change
Currently, alias over alias creates an extra expression layer, which gets merged in
optimize_projectionsthrough an expensive recursive functionWhat changes are included in this PR?
A small change to reuse an existing alias when possible. This affects two cases:
optimize_projectionsisn't called (e.g., when there's only one projection andmerge_consecutive_projectionsisn't run)Are these changes tested?
Extended doctest
Are there any user-facing changes?
No.