Skip to content

[datafusion] Support materialized views over ordinary append tables - #1584

Merged
JingsongLi merged 1 commit into
apache:mainfrom
JingsongLi:codex/datafusion-append-materialized-views
Dec 4, 2026
Merged

JingsongLi merged 1 commit into
apache:mainfrom
JingsongLi:codex/datafusion-append-materialized-views

Conversation

@JingsongLi

Copy link
Copy Markdown
Contributor

Purpose

Allow DataFusion to register materialized views over ordinary Paimon append tables. Spark can refresh these views against the same catalog and warehouse. Apache Paimon #11670

Brief change log

  • Accept native Paimon append sources with or without Data Evolution or row tracking. Validate that each source is at its branch head and has query authorization disabled.
  • Cover a filtered projection, a grouping over a fixed-bucket append source, and an inner join with a Data Evolution source. Check that primary-key tables, historical reads, and query-authorized sources are rejected during registration.

Tests

  • All 461 paimon-datafusion library tests passed.
  • cargo fmt --all -- --check and git diff --check passed.
  • A local Filesystem Catalog smoke test with Spark 4.1.4 verified the first refresh, a second refresh after appending rows, and DataFusion readback for a filtered projection and a grouped view.

API and Format

CREATE MATERIALIZED VIEW derives the output schema and creates an empty Parquet Data Evolution backing table with deletion vectors. Spark populates and refreshes it.

Documentation

Updated the SQL guide and DataFusion README to describe ordinary append sources and the Spark connector requirement.

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed base main at head ffcfe94 (+89/-23, 3 files): crates/integrations/datafusion/README.md, crates/integrations/datafusion/src/sql_context.rs, docs/src/sql.md.

This is the DataFusion registration counterpart of apache/paimon#11670 (already merged): the source gate in materialized_view_planning_catalogs replaces the data_evolution_enabled() requirement with !table_schema.primary_keys().is_empty() rejection, so any Paimon append table (with or without row tracking / Data Evolution) can back a materialized view. No core crate changes; the relaxation is confined to the DataFusion SQL layer, and refresh semantics stay owned by Spark.

Analysis:

  • The remaining guards are preserved: TableType::Table (no nested materialized/format tables), no time-travel selector (branch head only), and no query authorization. Primary-key tables are now the explicit rejection criterion, which matches the Spark-side AppendOnlyFileStoreTable gate; a PK table with write-only or DV configurations can no longer slip through as an append source.
  • The backing table creation is unchanged: DE + row tracking + DV, bucket -1, Parquet, materialized-table.definition-query, reserved source_row_id output check, and the double-quote token rejection all still apply, so views registered here remain refreshable by Spark under the same contract as before.
  • Planning still registers EmptyTable schemas from physical columns only, so wildcard expansion and name resolution match Spark refresh behavior for ordinary append sources as well.
  • Tests cover the three supported shapes from #11670 (filtered projection, GROUP BY over a fixed-bucket partitioned append source, inner join with a DE peer), assert the stored definition query and materialized-table options, and verify rejection of primary-key, historical-read, and query-authorized sources plus the no-source case. The error messages are updated consistently in both the code and the tests.
  • Docs correctly state the supported query shapes, the with/without row tracking support, and the connector requirement (a build including #11670, Spark 4.1/4.2/4.3).

No findings. The author reports all 461 paimon-datafusion library tests, fmt checks, and a local Filesystem Catalog smoke test with Spark 4.1.4 (first refresh, second refresh after appends, DataFusion readback) passing.

CI note: all checks green (builds and units on Linux/macOS/Windows, all integration suites including datafusion, MSRV, check).

LGTM.

@JingsongLi
JingsongLi merged commit 5687ba4 into apache:main Dec 4, 2026
15 checks passed
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