You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suport unparsing LogicalPlan::Window to SQL #10664
Is your feature request related to a problem or challenge?
Part of #9726 to complete the LogialPlan --> SQL conversion
Converting LogicalPlan back to SQL is valuable for several usecases such as using DataFusion to programatically create SQL -- see the plan_to_sql.rs example
Describe the solution you'd like
Support converting SQL with window functions like this:
SELECT first_value OVER (x ORDER BY y) FROM foo;
Describe alternatives you've considered
The basic pattern is this (see #10371 for an example):
Implement the LogicalPlan --> AST reverse code in Unparser::plan_to_sql(source link)
Add a test in roundtrip_statement in sql_integration.rssource link
Note you can run the tests like
cargo test -p datafusion-sql -- roundtrip_statement
Additional context
I think this is a good first issue as the pattern is well established and there are explicit instructions
I tried to implement for a while and I have a question,
for selecting a window function, there would be an projection.
> explain SELECT first_value(y) OVER (ORDER BY x) FROM foo;
| logical_plan | Projection: FIRST_VALUE(foo.y) ORDER BY [foo.x ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW |
| | WindowAggr: windowExpr=[[FIRST_VALUE(foo.y) ORDER BY [foo.x ASC NULLS LAST] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]] |
| | TableScan: foo projection=[x, y] |
Activity
yyy1000 commentedon May 28, 2024
I'd like to take it if no one picks it today. :)
yyy1000 commentedon May 29, 2024
I tried to implement for a while and I have a question,
for selecting a window function, there would be an projection.
However, for an aggregate, there's not.
In my understanding, window function is a special case of aggregate function, why would these two have different plan struct?
alamb commentedon May 29, 2024
I think window funtions and aggregate functions are different. Somewhat confusingly is that you can use aggregate functions as window functions
Window functions always have an
OVERclause.So for example, this is a normal aggregate
However, this is count being used as a window aggregate:
devinjdangelo commentedon Jun 2, 2024
I took a stab at this in #10767. It can be handled similarly to how we currently handle LogicalPlan::Aggregate.