fix(data-warehouse): derive partition count in compact threshold check - #70549
Merged
Conversation
Only md5 partitioning persists a partition_count on the schema; datetime- and numerical-partitioned schemas pass None, which made compact_if_fragmented treat those tables as one partition, so any table with more than 200 total files read as fragmented and got a defensive compact+vacuum at the start of every sync run. Derive the count from the distinct file directories in the delta log instead — no extra I/O, and all run_maintenance callers benefit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
danielcarletti
marked this pull request as ready for review
July 13, 2026 19:29
Contributor
|
Reviews (1): Last reviewed commit: "fix(data-warehouse): derive partition co..." | Re-trigger Greptile |
2 tasks
Gilbert09
approved these changes
Jul 14, 2026
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.
Problem
compact_if_fragmenteddecides "fragmented" from files-per-partition, using thepartition_countits caller passes. Only md5 partitioning persists apartition_counton the schema — datetime- and numerical-partitioned schemas never get one (append_partition_key_to_tableonly produces a count for md5 bucketing), sorun_pre_write_defensive_compactpasses None for them. With None the threshold math treats the table as a single partition, so any datetime-partitioned table with more than 200 total files reads as fragmented and gets a defensive compact plus vacuum at the start of every sync run, even when it is perfectly healthy.This is the same blind spot #70499 fixed for the CDC post-load path by deriving the count at its call site. This PR moves the derivation into
compact_if_fragmenteditself, so everyrun_maintenancecaller (the v2 and v3 pre-write defensive path today) gets the correct math without each call site reimplementing it.Changes
When
partition_countis None,compact_if_fragmentedderives it from the table's actual layout: the number of distinct file directories in the delta log's file paths (one directory per partition value; unpartitioned tables collapse to the single table root). No extra I/O — it reuses theget_file_urisresult the threshold math already fetched.Note
Behavior change: partitioned tables whose schemas persist no
partition_countstop compacting at the start of every sync run and only compact when genuinely past the thresholds (200 files per partition, 5,000 total). The total-files backstop is unaffected.Checked that no open PR touches this function: #70495 edits the merge-loop region and #70504 the commit-metadata region of the same file, both away from
compact_if_fragmented. Once this and #70499 both land, the call-site derivation inpipelines/common/load.pybecomes redundant (passing a non-None count simply skips the helper's derivation) and can be dropped in a small cleanup.How did you test this code?
Extended
TestCompactIfFragmentedintest_delta_table_helper.py:healthy_partitioned_table_skips: 300 files across 3 partition directories withpartition_count=Nonemust not compact — this case fails on the old code (None meant 1 partition, 300 files-per-partition, compact every run), so it pins exactly the regression this PR fixes.fragmented_partitioned_table_fires: 750 files across 3 directories (250 per partition) still compacts — guards the derivation from over-suppressing real fragmentation.The derivation lives in the helper, so the coverage lives there too — an extract-level test with a mocked helper cannot observe it, and the existing
TestRunPreWriteDefensiveCompactpass-through cases (schema over resource, both-None passes None) remain correct as-is.Ran locally:
pytest .../pipelines/pipeline/test/test_delta_table_helper.py .../pipelines/common/test/test_extract.py(74 passed).hogli ci:preflight --fixclean.Automatic notifications
Docs update
None needed, internal pipeline behavior only.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Follow-up flagged while working on #70499, implemented by Claude Code (Claude Fable 5). Skills invoked: /writing-tests. The task allowed either a call-site fix in
run_pre_write_defensive_compactor moving the derivation intocompact_if_fragmented; I (Claude) chose the helper after verifying the two open PRs touchingdelta_table_helper.py(#70495, #70504) edit disjoint function regions — one implementation fixes all callers and avoids a second copy of the derivation block. Branched from fresh master, independent of #70499.