Skip to content

[spark] Incrementally refresh Data Evolution inner join materialized views - #11559

Merged
JingsongLi merged 7 commits into
apache:masterfrom
JingsongLi:codex/paimon-spark-mv-inner-join
Nov 30, 2026
Merged

JingsongLi merged 7 commits into
apache:masterfrom
JingsongLi:codex/paimon-spark-mv-inner-join

Conversation

@JingsongLi

Copy link
Copy Markdown
Contributor

Purpose

Extend the materialized view SQL introduced in #11544 to support a single equality INNER JOIN between two Data Evolution tables.

The refresh pins both source snapshots and reads affected keys from their previous and current versions. Spark evaluates the old and new joins for those keys. Paimon applies the signed multiplicity of each projected row using the existing ROW write and deletion-vector path, then publishes both source positions with the refreshed data in one target snapshot.

The first version supports one same-type physical scalar key and a deterministic projection with an optional WHERE clause. It can rebuild when the required source history is unavailable, the source read schema changes, or the affected keys or result delta exceed the incremental budget. The Spark materialized views guide is updated in a separate commit.

Tests

  • Passed 204 focused Java tests and 44 Spark 4.1 SQL tests, including the existing single-source refresh suite.
  • Join regression coverage includes initial population, changes on both inputs between refreshes, key changes, DV deletes, duplicate results, schema-only changes, and pruning files for unaffected keys.
  • The Spark 3 common module compiled from clean output, and the Docusaurus documentation build passed.

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed base master at head b4a90c8. Full file list: docs/docs/spark/materialized-views.md; paimon-core main: new DataEvolutionMaterializedJoinRefresh, DataEvolutionMaterializedTableRefresh, new MaterializedSource, ProjectedRowDelta, RowIdAlignedMaterialization; core test: DataEvolutionMaterializedTableRefreshTest; paimon-format main: avro/FieldReaderFactory, row/RowBlockReader; Spark: new DataEvolutionMaterializedJoinViewTest.scala, DataEvolutionMaterializedViewTest.scala, new SparkMaterializedInnerJoin.scala, SparkMaterializedView.scala, SparkMaterializedViewTable.scala.

Core change notice: this PR extends generic paimon-core materialization semantics beyond the Spark feature. (1) validateTarget now accepts Parquet/ORC/Avro in addition to ROW for all materialized targets, and CREATE no longer forces the ROW format. (2) RowIdAlignedMaterialization now writes typed zero values for non-nullable fields at DV-masked positions instead of an all-null GenericRow, because compaction rewrites masked positions and columnar formats enforce NOT NULL. (3) ProjectedRowDelta.deleteFilter drops CHAR/VARCHAR from pruning (string statistics can alter comparison bounds) and conjoins per-column IN filters with a per-column value limit. (4) paimon-format Avro and ROW map readers switch from HashMap to LinkedHashMap so re-serialization preserves on-disk map order; this changes generic read behavior for every Avro/ROW map consumer, which is exactly what binary value matching needs. (5) The single-source pinning/progress logic is extracted into MaterializedSource and the projected-delta commit path into shared static helpers now also used by the new two-source join refresher.

Analysis:

  • Join key collection is complete: keys are gathered from changed row-ID ranges in both the previous and current snapshots of both sources, so any row whose contribution to the join result changes contributes its key in at least one version. The per-side scan predicate is a necessary condition of the WHERE (references restricted to one relation), so pruning never drops a qualifying row. Null keys are correctly skipped for inner-join equality. Budgets (128 keys / 4MiB) and unavailable history fall back to a full rebuild.
  • Signed-zero and string semantics are handled carefully: file-level IN pruning is only applied for types where binary comparison matches Spark equality (floating point excluded, strings excluded except partition keys with lossless literal round-trip), while the exact restriction uses Catalyst InSet with Spark semantics, which closes the equivalence class on both sides. The signed-zero tests cover both the WHERE and partition-pruning paths. Key types are restricted at binding to same-type physical scalar columns; the StringType pattern only matches binary collation, consistent with the documented scope.
  • The delta evaluation pins splits and read schemas through KnownSplitsTable and disables Paimon predicate pushdown on the Spark scan so Catalyst applies exact predicates; the driver budget uses widened decimal multiplication of row bytes by absolute multiplicity and respects spark.driver.maxResultSize, falling back to a distributed rebuild before collect.
  • Multiset application reuses the reviewed single-source path: findProjectedDeletes matches removed values against the pinned target base and returns false before any commit when a value cannot be fully matched, so the rebuild fallback never leaves a partial commit. Empty deltas still publish both source positions via the non-null RefreshState path, and the unchanged fast path additionally requires state equality to handle identity-qualification changes.
  • sameSource rejects self-joins including local path aliases (Files.isSameFile), and the identity fallback qualification handles filesystem catalogs that assign colliding fallback UUIDs across warehouses; both have dedicated tests.
  • The MV read path now partitions pushed predicates into safely prunable ones and residuals, marking post-scan predicates so Spark re-evaluates string/float comparisons that Paimon file statistics cannot honor exactly.
  • The MaterializedSource extraction preserves the previous single-source semantics: UUID plus schema-hash matching, cache invalidation for rollbacks through other handles, and planner dependencies from the projected field IDs.

No findings. Test coverage is strong: both-side changes with key moves and DV deletes, key absent from the result, schema-only changes, partition and WHERE pruning, signed zero, exact string bytes outside Parquet bounds, map order across full and incremental writes, same-named sources in different warehouses, and both driver budget fallbacks.

CI note: no checks reported on the head branch yet. The PR description records 204 focused Java tests, 44 Spark 4.1 SQL tests including the existing single-source suite, a clean Spark 3 common-module compile, and the docs build. Approving without waiting for CI.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants