yyanyy opened a new pull request, #60429:
URL: https://github.com/apache/spark/pull/60429
### What changes were proposed in this pull request?
Capture three SQL configuration defaults when `to_json`, `to_csv`, and
`from_json` expressions are constructed, so views and SQL functions use their
saved definition settings when their writers or parsers are initialized later:
- `spark.sql.jsonGenerator.ignoreNullFields`
- `spark.sql.legacy.nullValueWrittenAsQuotedEmptyStringCsv`
- `spark.sql.legacy.json.enableDateTimeParsingFallback`
The captured values survive expression copies and serialization. Explicit
function options retain precedence, including case-insensitive option names.
CSV option maps retain their existing null-as-unset behavior. JSON parsing
fallback preserves unset, true, and false: unset continues to derive its
behavior from the parser policy and whether a custom date or timestamp format
is present. File-source callers retain their existing defaults.
### Why are the changes needed?
Views and SQL functions restore saved SQL configurations while analyzing
their bodies, but these functions create their writers and parsers later.
Reading option defaults at that point uses the reader's configuration and can
change JSON fields, CSV null quoting, or parsed dates and timestamps.
### Does this PR introduce _any_ user-facing change?
Yes. Queries against views and SQL functions honor their captured defaults
for these three settings. For example:
```sql
SET spark.sql.jsonGenerator.ignoreNullFields=false;
CREATE VIEW captured_json AS
SELECT to_json(named_struct('id', id, 'n', CAST(NULL AS INT))) AS value
FROM range(1, 2);
SET spark.sql.jsonGenerator.ignoreNullFields=true;
SELECT value FROM captured_json;
```
Previously the query returned `{"id":1}`. With this change it returns
`{"id":1,"n":null}`, matching the view's creation setting. The corresponding
CSV case preserves quoted null fields, and JSON parsing preserves the
definition's fallback setting rather than returning different timestamps under
reader configurations.
### How was this patch tested?
Added Catalyst expression tests for captured defaults across copies,
time-zone resolution, serialization, and evaluation paths, plus SQL tests for
permanent views and SQL functions, reader configuration changes, explicit
option precedence, and unset/true/false JSON fallback behavior.
Before the production change, all seven initial `JsonCsvOptionsConfSuite`
regressions failed behaviorally against the unmodified source.
All 392 tests passed across the ten selected suites, including the 26
view/function regressions and nine expression regressions:
```sh
build/sbt \
'catalyst/testOnly *JsonCsvOptionsConfSuite *JsonExpressionsSuite
*CsvExpressionsSuite *OptimizeJsonExprsSuite *OptimizeCsvExprsSuite' \
'sql/testOnly *JsonCsvOptionsSQLConfSuite *JsonFunctionsSuite
*CsvFunctionsSuite *JsonParsingOptionsSuite *CSVParsingOptionsSuite'
```
The original seven expression regressions and all 26 SQL regressions failed
with incorrect values before the production changes. Validation used a native
SBT build with Java 25.0.4.1. Scala style checks also passed with zero errors
and warnings for Catalyst production/tests and SQL tests:
```sh
build/sbt 'catalyst/scalastyle' 'catalyst/Test/scalastyle'
'sql/Test/scalastyle'
```
The full Spark test suite was not run.
### 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]