expose SpjNormalForm::predicate() + Predicate Display impl#120
Merged
xudong963 merged 2 commits intoJun 25, 2026
Merged
Conversation
`SpjNormalForm` already exposes public getters for `output_schema`,
`output_exprs`, and `referenced_tables`, but the `predicate` field is
private. Downstream consumers that want to surface the SPJ normal form
(e.g. atlas catalog tables exposing `mv_normal_form` for debugging why
view matching does or does not engage) currently have to walk the
original `LogicalPlan` and re-collect Filter / TableScan filters as a
string, which loses the normalization the analyzer applied.
This change:
* Promotes `Predicate` and `ColumnEquivalenceClass` from private to
`pub` so they can be referenced from public APIs.
* Adds `pub fn predicate(&self) -> &Predicate` on `SpjNormalForm`.
* Adds a `Display` impl on `Predicate` that AND-joins:
- pairwise equalities derived from each multi-column equivalence
class (singletons emit nothing),
- narrowed range intervals per equivalence class (classes whose
interval is still the default unbounded interval are skipped, so
only meaningful constraints surface),
- residual filter expressions, sorted for deterministic output.
The internal fields stay private, so this does not lock in any
particular representation; only the read-only view is published.
A unit test exercises the new getter + Display on a predicate that
populates all three buckets (eq class, range, residual).
There was a problem hiding this comment.
Pull request overview
This PR exposes the normalized filter predicate from SpjNormalForm so downstream consumers can surface/debug the analyzer’s SPJ-normalized filters, and adds a human-readable Display rendering for that predicate.
Changes:
- Adds
pub fn predicate(&self) -> &PredicatetoSpjNormalForm. - Promotes
PredicateandColumnEquivalenceClasstopuband implementsDisplayforPredicate. - Adds a new unit test covering the getter +
Display.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Reword the `Predicate` doc comment so it no longer implies field accessors that don't exist; describe the internal buckets instead. - Make `Display for Predicate` render `FALSE` when any equivalence class has an empty range (`None` in `ranges_by_equivalence_class` after a prior `Interval::intersect` collapsed). Previously the unsatisfiable predicate looked identical to "no filter", which is misleading for catalog surfacing. - Revert `pub struct ColumnEquivalenceClass` to `struct`; the type is not referenced from any public signature, so keeping it private avoids needlessly expanding the crate's public surface. - Add `debug_assert!` calls on the in-loop `continue` paths in Display that fire only on broken internal invariants (length mismatches, empty classes, missing schema entries). The intentional unbounded skip stays a silent continue. - Strengthen `test_predicate_getter_and_display` so it actually asserts the range bucket (the `a >= 5` narrowing) renders, not just the equality + residual buckets.
xudong963
approved these changes
Jun 25, 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.
Summary
SpjNormalFormalready exposes public getters foroutput_schema,output_exprs, andreferenced_tables, butpredicatestays private. Downstream consumers that want to surface the SPJ normal form via catalog metadata or for debugging view-matching engagement currently have to walk the originalLogicalPlanand re-collectFilter/TableScan.filtersthemselves, which loses the normalization the analyzer applied.This PR closes that gap:
PredicateandColumnEquivalenceClassfrom private topubso they can be referenced from public APIs.pub fn predicate(&self) -> &PredicateonSpjNormalForm.Displayimpl onPredicatethat AND-joins the three internal buckets the subsumption tests already use:ExprDisplayand sorted for deterministic output.The internal fields stay private, so this does not lock in any particular representation -- only the read-only view is published.
Motivation
Downstream of this crate (in atlas), we are exposing two catalog tables
meta.mv_normal_form/meta.mv_candidate_mapso engineers can inspect why view matching does or does not engage on a given table (e.g., why istickers_by_market_inactive_v1only a partial-coverage MV? Answer: it carriesactive = false). The current workaround walks the un-normalizedLogicalPlan, which works but mirrors the analyzer's job. Routing through the normalized predicate keeps the catalog output consistent with what the matcher actually consumes.Tests
Existing 21 tests pass. Adds one new test
test_predicate_getter_and_displaythat exercises the new getter + Display on a predicate populating all three buckets (equality class, range, residual).