Repository navigation
[spark] Incrementally refresh outer, semi and anti join materialized views - #11566
Conversation
leaves12138
left a comment
There was a problem hiding this comment.
Reviewed base master at head e895838. Full file list: docs/docs/spark/materialized-views.md; paimon-core main: DataEvolutionMaterializedJoinRefresh, MaterializedSource; Spark: DataEvolutionMaterializedJoinViewTest.scala, SparkCatalog.java, SparkMaterializedInnerJoin.scala renamed to SparkMaterializedJoin.scala, SparkMaterializedView.scala.
Core change notice: this PR extends the generic two-source refresh contract in paimon-core. Source gains preservesUnmatchedRows, collectKeys now returns per-input NULL-key ranges instead of a boolean, JoinQuery gains a defaulted six-argument delta overload (existing four-argument implementations keep working), and MaterializedSource gains previouslyEmpty so a saved empty position can bootstrap incrementally from range [0, nextRowId-1] instead of forcing a full rebuild. The full-refresh path now decides canProduceRows from which sides preserve unmatched rows rather than requiring both snapshots. These are shared materialization semantics, not just Spark wiring.
Analysis:
- NULL-key completeness: a NULL-key row on a preserved side contributes a null-extended (or anti-join) output row that depends only on itself, so scanning NULL keys restricted to that input's changed row-ID ranges in both versions is sufficient; unchanged NULL rows inside the ranges appear in both signed evaluations and cancel. The shared key set only receives a NULL entry when some preserved side actually saw a NULL change, and the Spark scan skips a side's NULL branch when its returned range list is empty, so unaffected NULL groups are never read (verified by the unavailable-file test).
- WHERE pruning gates are correct per join type: pruning an input by a single-side predicate is only enabled where that side's columns pass through unextended (left for Inner/LeftOuter/LeftSemi/LeftAnti, right for Inner/RightOuter, neither for FullOuter). This avoids the trap where a predicate on a null-extended side observes match status. Spark still evaluates the exact WHERE on the join result.
- The non-null key scan now pushes isNotNull even when file comparison cannot honor Spark equality, which is a safe superset; exact membership stays with Catalyst InSet. Null and non-null branches are combined with Union, and an empty branch list becomes an empty LocalRelation.
- Bootstrap from a saved empty position is sound: previousId=0 with no UUID and the same schema means every live row at the new head is new, the before side evaluates as an empty relation, and keys from the other side's normal change planning complete the union. A missing nextRowId or schema change still falls back to a full rebuild.
- canProduceRows correctly distinguishes joins that can emit rows with one absent source (preserved side present) from inner/semi joins that cannot, while still publishing both source positions through the non-null RefreshState path.
- Blocking ALTER of materialized-table.definition-query in SparkCatalog closes a real correctness hole: changing the stored definition without rebuilding would silently reinterpret existing data. The rejection test covers both SET and UNSET.
- Binding still requires exactly one ordinary EqualTo between same-type physical keys; <=>, compound conditions, and non-equality joins are rejected with tests.
No findings. The nine new regressions cover one-sided bootstrap, first/last match transitions, moves to NULL on both inputs, duplicate membership and duplicate projected results without the join key, null-extended WHERE, and the rejection paths, and they assert both source positions and target row-ID advancement.
CI note: no checks reported on the head branch yet. The PR description records the focused Java and Spark 4.1 Maven suites, the Spark 3 profile compile, and the docs build. Approving without waiting for CI.
LGTM.
Purpose
Build on #11559 to refresh Spark materialized views incrementally for LEFT, RIGHT, and FULL OUTER joins and LEFT SEMI and LEFT ANTI joins over two Data Evolution tables. Each definition uses one
=between same-type physical keys.The refresher reads affected keys from changed row-ID ranges in the previous and current source snapshots, evaluates both versions of the join for those keys, and applies signed result-row multiplicities. Preserved sides contribute unmatched rows with NULL keys, and an input without a snapshot is treated as empty. Spark evaluates WHERE on the join result where null extension can affect the predicate. Both source positions are committed with the target changes.
The Spark materialized views guide is updated in a separate commit.
Tests