punya opened a new pull request, #27682:
URL: https://github.com/apache/datafusion/pull/27682
## Which issue does this PR close?
- Closes #27680.
- Closes #27681.
## Rationale for this change
These queries now work:
```sql
SELECT * FROM (VALUES (1, 10), (1, 20), (2, 30)) AS t(k, v)
|> EXTEND ROW_NUMBER() OVER (PARTITION BY k ORDER BY v DESC) AS rn
|> WHERE rn = 1;
-- (1, 20, 1), (2, 30, 1)
SELECT [1, 2, 3] AS xs
|> SELECT unnest(xs) AS x;
-- 1, 2, 3
```
Before this change, a window function in `|> SELECT` or `|> EXTEND` failed
("Window function ... is not supported in this position"), and `unnest`
failed
in type coercion ("Unnest should be rewritten to LogicalPlan::Unnest before
type
coercion"). Both work without pipes.
## What changes are included in this PR?
`|> SELECT` and `|> EXTEND` built a plain projection. They now go through a
new
private helper, `pipe_operator_project`, which plans the expressions the way
`select_to_plan` does: a `Window` node for any window functions (via
`LogicalPlanBuilder::window_plan` and `rebase_expr`), then
`try_process_unnest` for the projection, which adds the `Unnest` node when
needed. The two issues share this code path, so they are fixed together.
## What is the testing strategy for this PR?
New cases in `pipe_operator.slt` cover `ROW_NUMBER`, `LAG` and `LEAD` in both
`|> SELECT` and `|> EXTEND`, and `unnest` in both.
## Are there any user-facing changes?
Window functions and `unnest` now work in `|> SELECT` and `|> EXTEND`. No
public
API changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]