[SPARK-55568][SQL] Separate schema construction from field stats collection#54343
Open
qlong wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-55568][SQL] Separate schema construction from field stats collection#54343qlong wants to merge 1 commit intoapache:masterfrom
qlong wants to merge 1 commit intoapache:masterfrom
Conversation
…ection Variant shredding schema inference is expensive and can take over 100ms per file. Replace fold-based schema merging with deferred schema construction using single-pass field statistics collection. Previous approach: - Used foldLeft to build and merge complete schemas for each row - Merged schemas repeatedly across 4096 rows - High allocation overhead from recursive schema construction New approach: - Separate schema construction from field statistics collection to avoid excessive intermediate allocations and repeated merges. - Single-pass field traversal with flat statistics registry to track field types and row counts - Using lastSeenRow for deduplication - Defers schema construction until after all rows processed Performance vs master: - Tested with scenarios with different field counts, array sizes, and batch sizes(1-4096 rows, 10-200 fields, varying nesting depths and sparsity patterns). - Average 1.5x speedup across test scenarios - 1.5x-1.6x faster on array-heavy workloads - 11.5x faster on sparse data (10% field presence) - Consistent performance across multiple runs - 96% of tests show improvement All existing unit tests pass. Issue: https://issues.apache.org/jira/browse/SPARK-55568
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.
Why are the changes needed?
Variant shredding schema inference is expensive and can take over 100ms per file. Replace fold-based schema merging with deferred schema construction using single-pass field statistics collection.
Previous approach:
New approach:
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Functional test:
Performance vs master:
Was this patch authored or co-authored using generative AI tooling?
Co-authored with Claude Sonnet 4.5