stevomitric opened a new pull request, #60061:
URL: https://github.com/apache/spark/pull/60061
### What changes were proposed in this pull request?
Mark the output of `UnionLoopRef` as nullable at every nesting level
(`dataType.asNullable`), not only at the top level. Also make
`LogicalRDD.buildOutputAssocForRewriteWithNewOutput` ignore nullability, so
`UnionLoopExec` keeps the previous iteration's stats and constraints.
### Why are the changes needed?
The self-reference keeps the anchor's nested types. If the anchor builds
`array(c)` or `map('k', c)` from a non-null column, NULLs written by the
recursive step are read back as 0 in the next iteration (or throw an NPE for a
NULL struct in an array):
```sql
CREATE TEMPORARY VIEW parts AS SELECT id AS cost FROM range(200);
WITH RECURSIVE t(lvl, arr) AS (
SELECT 0, array(cost) FROM parts
UNION ALL
SELECT lvl + 1, IF(lvl = 0, array(CAST(NULL AS BIGINT)), array(arr[0] +
1)) FROM t WHERE lvl < 2
)
SELECT lvl, count_if(arr[0] IS NULL) FROM t GROUP BY lvl ORDER BY lvl;
-- before: 0 0 / 1 200 / 2 0
-- after: 0 0 / 1 200 / 2 200
```
### Does this PR introduce _any_ user-facing change?
Yes, such queries now return NULL instead of 0 or an NPE.
### How was this patch tested?
- New cases in `cte-recursion.sql` (array, map, struct, array of structs).
- New tests in `ResolveRecursiveCTESuite` and `StatisticsCollectionSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Isaac (Claude Opus 5.5)
--
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]