[SPARK-59417][SQL] Stream multiline top-level JSON arrays - #58704
Open
tdcmeehan wants to merge 6 commits into
Open
[SPARK-59417][SQL] Stream multiline top-level JSON arrays#58704tdcmeehan wants to merge 6 commits into
tdcmeehan wants to merge 6 commits into
Conversation
tdcmeehan
marked this pull request as ready for review
September 11, 2026 00:22
Member
|
Mind taking a look at https://github.com/apache/spark/pull/58704/checks?check_run_id=103066275835? |
Author
|
@HyukjinKwon done, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR adds the internal Spark SQL configuration
spark.sql.json.enableStreamingTopLevelArray. When enabled, multiline JSON reading consumes a top-level array of structs lazily from one Jackson parser instead of materializing the entire array before returning rows. The configuration defaults to false so the behavior can be rolled out safely.It also adds an opt-in lazy path to
FailureSafeParserfor failures raised while advancing the parser iterator, preserves rows emitted before later structural corruption, and adds benchmark cases for both many small elements and fewer large elements. Existing eagerFailureSafeParsercallers remain unchanged.Why are the changes needed?
The existing parser materializes every element of a multiline top-level JSON array in memory. Large arrays can therefore require memory proportional to the complete document even though Spark consumes the result as an iterator. Streaming elements bounds parser-side memory while retaining the existing valid-row and parse-mode behavior. The SQL configuration permits staged adoption of the new parsing path.
Does this PR introduce any user-facing change?
Yes, when
spark.sql.json.enableStreamingTopLevelArrayis enabled. Reading a multiline top-level JSON array no longer materializes the complete array before producing rows. If malformed structure is encountered after valid rows have already been emitted, those rows remain available and the malformed document is then handled according to the configured parse mode. The configuration is disabled by default.How was this patch tested?
Added regression coverage for both SQL configuration values, lazy top-level array parsing, and malformed input after partial output under PERMISSIVE, DROPMALFORMED, and FAILFAST, and extended the existing SPARK-3308 top-level-array coverage.
Ran:
sql/Test/compilesql/testOnly org.apache.spark.sql.execution.datasources.json.JsonV1Suite(162 tests)sql/testOnly org.apache.spark.sql.execution.datasources.json.JsonV2Suite(163 tests)catalyst/scalastylesql/scalastylesql/Test/scalastylegit diff --checkThe focused OSS benchmark can be run with:
The benchmark reads multiline JSON through the data source with
spark.sql.json.enableStreamingTopLevelArraydisabled and enabled. On OpenJDK 17.0.15 and Intel Xeon 6975P:Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)