Core, Spark 4.1: Add compute_sort_order_stats procedure to measure sort-key file overlap - #17504
Open
gimgit wants to merge 2 commits into
Open
Core, Spark 4.1: Add compute_sort_order_stats procedure to measure sort-key file overlap#17504gimgit wants to merge 2 commits into
gimgit wants to merge 2 commits into
Conversation
3 tasks
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.
Relates to #17489.
What
Adds a read-only Spark procedure
compute_sort_order_statsthat reports, per partition, how well the data file layout matches the table's declared sort order:max_overlap_depthavg_overlap_depthfile_count/files_missing_boundsWhy
As described in #17489,
rewrite_data_filescandidate selection considers only file size, so a table whose files are all within the healthy size band is permanently excluded from sort/z-order compaction — the job reports success on every run while sort-key overlap never improves. Today there is no way to detect this state: every size-based health metric reports such a table as perfectly healthy. This was also the missing piece asked in #12761 ("Do you have a way to identify the non-sorted files somehow?").This PR intentionally starts with measurement only (no planner/selection changes), so operators can detect the state and decide when to trigger a
rewrite-all/filtered rewrite. A follow-up could add an opt-in selection option as sketched in #17489.How
SortOrderStatsHandler(core): computes overlap depth purely from data file metadata (lowerBounds/upperBoundsof the first sort field) via a sweep line over[lower, upper]ranges — no data files are opened, nothing is committed.ComputeSortOrderStatsProcedure(Spark 4.1): thin read-only wrapper returning one row per partition. Scoped to Spark 4.1 first; happy to backport to 4.0/3.5 if this lands.Actionlayer: the computation is driver-side metadata-only, so the procedure calls the core handler directly (same pattern as other read-only procedures). Can add the action layer if preferred.Testing
TestSortOrderStatsHandler(core, 10 cases): full overlap, disjoint, touching boundaries, partial overlap, missing bounds (partial/all), single file, unsorted table, non-order-preserving transform,snapshot_idtime travelTestComputeSortOrderStatsProcedure(spark-extensions, 6 cases × 4 catalogs): empty table, unsorted failure, overlap/disjoint reporting, per-partition reporting,snapshot_id