Repository navigation
Conversation
sezruby
force-pushed
the
stats-aware-compaction-binning
branch
from
October 6, 2026 20:51
8de554e to
4596f79
Compare
Add an opt-in lightweight tier to OPTIMIZE and auto compaction on clustered tables. While the table has some unclustered data, but less than spark.databricks.delta.optimize.clustering.lightweight.maxUnclusteredBytes, OPTIMIZE compacts only the small unclustered files instead of clustering: clustered files and partial Z-cubes are not rewritten, and rows are not sorted. Candidate files are ordered by the per-file min/max statistics of a single clustering column before they are packed into bins, so each output file covers a narrow range of that column. The column is configurable, or picked as the clustering column whose files overlap least. Output files stay unclustered and are clustered once enough unclustered data has accumulated. OPTIMIZE FULL always clusters. Configs: - optimize.clustering.lightweight.enabled (default false) - optimize.clustering.lightweight.maxUnclusteredBytes (default 10GB) - optimize.clustering.lightweight.column (default: auto-pick) - optimize.clustering.lightweight.maxRelativeFileRange (default 0.5) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sezruby
force-pushed
the
stats-aware-compaction-binning
branch
from
October 7, 2026 05:34
4596f79 to
4fcdc8d
Compare
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.
Which Delta project/connector is this regarding?
Description
Adds an opt-in lightweight compaction tier to
OPTIMIZEand auto compaction on clustered (liquid) tables.Motivation
Today, incremental
OPTIMIZEon a clustered table:minCubeSize, 100 GB by default);Any unclustered file makes the partial cubes eligible again. So on tables that get small batches between frequent
OPTIMIZEor auto compaction runs, a little new data can rewrite up to ~100 GB of already-clustered data on every run. That is high write amplification, plus a full shuffle each time.Change
When
spark.databricks.delta.optimize.clustering.lightweight.enabledis true, and the table has some unclustered data but less than...lightweight.maxUnclusteredBytes,OPTIMIZEuses a newLightweightClusteringStrategyinstead ofClusteringStrategy:(min, max)stats of a single clustering column before bin packing, so each output file covers a narrow range of that column. Rows are not sorted; each bin is coalesced, as in plain compaction....lightweight.column. Otherwise it is auto-picked as the clustering column whose files overlap least. The overlap is measured on ranks of the distinct min/max values, so it works for any orderable type. If no column's average relative file range is at most...lightweight.maxRelativeFileRange, files are grouped by size. One column is used because grouping whole files cannot keep several columns narrow at once; full clustering handles the rest.clusteringProvideror Z-cube tags. They are clustered once enough unclustered data has accumulated. The commit recordsclusterBy=[], so lightweight runs can be told apart in history.OPTIMIZE FULL, during REORG, at or above the threshold, and when there is no unclustered data (so partial cubes can still merge).spark.databricks.delta.prefix)optimize.clustering.lightweight.enabledfalseoptimize.clustering.lightweight.maxUnclusteredBytesoptimize.clustering.lightweight.columnoptimize.clustering.lightweight.maxRelativeFileRange0.5Defaults leave current behavior unchanged.
Prior art
INSTANT_TIME).This change generalizes that idea to a stats-chosen clustering column, as a cheap tier in front of full clustering.
How was this patch tested?
New
LightweightClusteringSuite(15 tests):Also ran
IncrementalZCubeClusteringSuite,ClusteringProviderSuite,OptimizeCompaction{SQL,Scala}Suite,OptimizeMetricsSuite,AutoCompact{Execution,Configuration}Suite,DeltaErrorsSuite,DeltaThrowableSuite, and scalastyle.Does this PR introduce any user-facing changes?
Yes, new opt-in SQL configs (documented in
delta-clustering.mdx). No behavior change by default.