dtenedor opened a new pull request, #60697:
URL: https://github.com/apache/spark/pull/60697
### What changes were proposed in this pull request?
SQL pipe operators `|> SELECT`, `|> EXTEND`, `|> SET` and `|> AGGREGATE`
reject the outer generators `explode_outer`, `posexplode_outer` and
`inline_outer` with `UNSUPPORTED_GENERATOR.NESTED_IN_EXPRESSIONS`, even when
the generator is a top-level item and nothing is nested:
```sql
CREATE TEMPORARY VIEW posts(post_id, tags) AS
VALUES (1, array('sql', 'spark')), (2, array('delta')), (3, array());
FROM posts |> SELECT post_id, explode_outer(tags) AS tag;
-- [UNSUPPORTED_GENERATOR.NESTED_IN_EXPRESSIONS] The generator is not
supported:
-- nested in expressions "pipeexpression(generatorouter(explode(tags)))".
```
The same query works with non-outer `explode`, and as a plain `SELECT
post_id, explode_outer(tags) AS tag FROM posts`.
Root cause: `ValidateAndStripPipeExpressions` strips the `PipeExpression`
wrapper only when `p.child.resolved`. The `*_outer` functions produce
`GeneratorOuter(g)`, whose `resolved` is always `false` because
`ExtractGenerator` is meant to replace it. So the wrapper stays, and
`ExtractGenerator` sees `Alias(PipeExpression(GeneratorOuter(...)))`. It then
treats the generator as nested inside another expression.
This PR also strips the wrapper when the child is a `GeneratorOuter` over a
resolved generator. The existing aggregate validation for pipe clauses still
runs unchanged on the stripped child.
### Why are the changes needed?
It fixes a bug where valid queries failed analysis. Pipe operators are meant
to accept the same expressions as the corresponding plain SQL clauses.
### Does this PR introduce _any_ user-facing change?
Yes. Pipe `SELECT`, `EXTEND`, `SET` and `AGGREGATE` items whose top-level
expression is an outer generator now return the same rows as the equivalent
plain SQL query instead of failing. Generators nested inside other expressions,
such as `upper(explode_outer(tags))`, are still rejected, and the pipe-specific
aggregate checks still apply.
### How was this patch tested?
Added cases to `pipe-operators.sql` and regenerated its golden files:
- Positive: `explode_outer` over arrays and maps, `posexplode_outer` and
`inline_outer` in `|> SELECT`; `explode_outer` in `|> EXTEND` and `|> SET`;
`explode_outer(collect_list(...))` in `|> AGGREGATE ... GROUP BY`; and
`explode_outer` over an empty global aggregate. The inputs include empty and
NULL arrays.
- Negative: a nested outer generator
(`UNSUPPORTED_GENERATOR.NESTED_IN_EXPRESSIONS`), `|> AGGREGATE` with no
aggregate function
(`PIPE_OPERATOR_AGGREGATE_EXPRESSION_CONTAINS_NO_AGGREGATE_FUNCTION`), and an
aggregate in `|> EXTEND` (`PIPE_OPERATOR_CONTAINS_AGGREGATE_FUNCTION`).
With the change to `pipeOperators.scala` reverted, the new golden-file cases
fail with `UNSUPPORTED_GENERATOR.NESTED_IN_EXPRESSIONS`. `SQLQueryTestSuite`
(pipe tests), `GeneratorFunctionSuite`, `PipeOperatorSuite`, the single-pass
resolver suites and scalastyle pass locally.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
--
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]