← Back to Pull requests

Share one partition-exclusion predicate across the caches #64

Closed
unknown closed this pull request without merging on Oct 01, 2026 16:53 UTC
View on GitHub
unknown unknown commented on Sep 27, 2026 20:20 UTC
Author

Summary

The column (cache), in-memory (cache_memory), and Parquet (cache_parquet) caches each built their own predicate to restrict a query to the not-yet-cached partitions — "exclude every known partition", i.e. ~OR(AND(col == value)). The three implementations had diverged in behavior:

| cache | null handling | is_in compression | contradiction-analyzable |
|---|---|---|---|
| cache (_extract_filter_from_df) | ne — not null-safe | ✅ (_repeated_grouping) | ✅ |
| cache_memory (_exclude_built) | eq_missing — null-safe | ❌ | n/a (never used) |
| cache_parquet (_build_not_existing_partitions_pred) | == — not null-safe | ❌ | — |

This consolidates all three into a single builder, util.partition_exclusion_predicate, with one consistent behavior:

  • Null-safe (eq_missing / a null-aware not in), so a null partition value excludes exactly its own rows.

  • Analyzable by the DNF contradiction detector — deliberately avoids fill_null, which is opaque to the analyzer and would defeat the "skip an impossible query" optimization. Uses only is_in / is_null / ne_missing, which the analyzer already understands (EQ_VALIDITY/NOT_EQ_VALIDITY/in/is).

  • Efficient — is_in + repeated grouping keep the expression small even with many partitions.
  • lazy_cache, lazy_cache_memory, and lazy_cache_parquet now all delegate to it.

    Behavior change: unfiltered reads restrict the discovery query

    cache() now excludes already-cached partitions even when there is no incoming predicate. Previously an unfiltered read over a fully-cached partitioned frame re-scanned the whole source; now it excludes the known partitions (mirroring cache_memory's build planner). The contradiction check is skipped when there is no incoming predicate (a bare exclusion is never a contradiction, and the check can be non-trivial).

    Null-safety fixes surfaced by the consolidation

    1. cache() fixed-partition scan (== p_val → eq_missing): fetching additional columns for a known null-valued partition returned no rows (col == None is null), producing mismatched column heights. This was previously masked by the full re-scan the new exclusion avoids. (Found in review.)
    2. cache_memory() carrier frame (infer_schema_length=None): a partition column that is null in the first keys but valued later inferred Null and failed to append the later value. (Found in review.)

    Validation

  • Full suite: 1636 passed, 43 skipped, 6 xfailed.

  • New tests: shared-builder unit tests (null-safe parity vs eq_missing, single/multi-column, contradiction-analyzability, dedup) + regression tests for both null-safety fixes and the unfiltered-exclusion behavior.

  • Reviewed (Sol): found the two null-safety bugs above (both fixed + regression-tested); re-review confirmed the fixes complete with no remaining issues.

  • At-scale stress test (up to 10k partitions / high-cardinality / multi-col cross-products / incremental worst case, with parquet data cleaned up after):

  • - The shared builder is not a bottleneck: exclusion build 0.016s and contradiction detection 0.026s at 50k partitions; expression stays compressed.
    - This PR introduces no perf regression: full-reread 1.281s (this branch) vs 1.310s (main), identical.
    - Independently confirmed on main: the pre-existing cache() cost at very high partition counts is the per-call cache-key traversal + block reassembly (already noted in a code comment), not the exclusion predicate — untouched here.

    Out of scope (pre-existing, confirmed on main)

    The stress test also surfaced pre-existing cache_parquet read-plan limitations (a col.is_null() or negative col != x / all-but-one filter over finite partitions can enumerate no paths and return 0 rows). These reproduce identically on main, live in the read-plan/partition-enumeration path (not the write-plan helper changed here), and are not addressed in this PR.

    Relation to #63

    Independent of #63 (column_granularity); both branch from main and touch different regions of cache(), so they merge cleanly in either order.

    Diff: 524 lines (+393 / -131) across 6 files Reviewer: timkpaine Review duration: 5553m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 524 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.375
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #64"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.9% · Safe to merge
    18.9%