n-young opened a new pull request, #60074:
URL: https://github.com/apache/spark/pull/60074
### What changes were proposed in this pull request?
Allow nested nulls in recursive CTE references before resolving recursive
expressions.
Coerce the recursive term using the anchor's element and field types while
permitting
wider nullability and preserving the anchor's struct field spelling.
Add eight small SQL regression cases for arrays, structs, maps, struct map
keys,
case-insensitive field matching, and rejection of wider recursive
element/field types.
The cases run with ANSI mode both enabled and disabled.
### Why are the changes needed?
A non-null anchor does not guarantee non-null values in later iterations.
Spark can
fold nested null checks to `false`, throw a `NullPointerException` for null
map values,
or reject compatible recursive structs that differ in nested nullability.
For example, the last row below currently reports `false` for `saw_null`; it
should
report `true` because the preceding iteration produced a null array element:
```sql
WITH RECURSIVE r(n, a, saw_null) AS (
SELECT 0, array(1), false
UNION ALL
SELECT n + 1, array(CAST(NULL AS INT)), exists(a, x -> x IS NULL)
FROM r WHERE n < 2
)
SELECT n, a, saw_null FROM r ORDER BY n;
```
### Does this PR introduce _any_ user-facing change?
Yes. Affected recursive queries return correct results instead of incorrect
null
predicates or errors. Recursive output schemas can have more nullable nested
fields;
recursive terms still cannot widen the anchor's element or field types.
### How was this patch tested?
Local validation: all 4 SQL execution/analyzer tests and all 126 Catalyst
tests passed.
Catalyst Scala style checks passed with zero errors or warnings.
```sh
build/sbt \
'sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z cte-recursion' \
'catalyst/testOnly
org.apache.spark.sql.catalyst.analysis.ResolveRecursiveCTESuite
org.apache.spark.sql.catalyst.analysis.TypeCoercionSuite
org.apache.spark.sql.catalyst.analysis.AnsiTypeCoercionSuite' \
'catalyst/Compile/scalastyle'
```
The new execution and analyzer goldens were generated through
`SQLQueryTestSuite`.
They capture correct null predicates and compatible struct coercion, while
retaining
errors for incompatible type widening. No existing golden files are changed.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6)
--
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]