Skip to content

Spec: Materialized View Spec - #11041

Open
JanKaul wants to merge 89 commits into
apache:mainfrom
JanKaul:materialized-view-spec
Open

JanKaul wants to merge 89 commits into
apache:mainfrom
JanKaul:materialized-view-spec

Conversation

@JanKaul

@JanKaul JanKaul commented Aug 29, 2024

Copy link
Copy Markdown

This PR implements the Iceberg Materialized View Proposal #10043 by adding a section for Materialized Views to the View spec. It follows the design of the proposal document.

The idea is to resolve any remaining questions before starting the voting process on the dev list.

@JanKaul

JanKaul commented Aug 29, 2024

Copy link
Copy Markdown
Author

@github-actions github-actions Bot added the Specification Issues that may introduce spec changes. label Aug 29, 2024
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
@JanKaul
JanKaul force-pushed the materialized-view-spec branch from 62ba549 to b986cf0 Compare September 19, 2024 09:08
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
bennychow

This comment was marked as outdated.

@JanKaul
JanKaul force-pushed the materialized-view-spec branch from 90f517e to 2790b0d Compare October 4, 2024 14:13
@JanKaul JanKaul mentioned this pull request Nov 8, 2024
3 of 6 tasks
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Nov 12, 2024
@github-actions

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Nov 19, 2024

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is the right direction, thanks @JanKaul. I think we should reopen. Also left some suggestions.

Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
Comment thread format/view-spec.md Resolved
@szehon-ho szehon-ho reopened this Nov 21, 2024
@JanKaul
JanKaul force-pushed the materialized-view-spec branch from 2790b0d to af76391 Compare November 21, 2024 10:53

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, one more minor suggestion

Comment thread format/view-spec.md Resolved
@github-actions github-actions Bot removed the stale label Nov 22, 2024
@JanKaul
JanKaul force-pushed the materialized-view-spec branch from af76391 to 521477f Compare November 25, 2024 07:33
@devozerov

Copy link
Copy Markdown
Member

When materialized view is created, two entities would be added to the catalog - a view and a storage table. From the engine perspective it is important to expose it as a single object during listing. Are there any rules how catalog implementors should deal with these objects? E.g., shall we expose the view via listViews, but filter-out the storage table for listTables?

@JanKaul

JanKaul commented Nov 25, 2024

Copy link
Copy Markdown
Author

Yes correct, the idea is to filter-out the storage-table for the listTables operation. But I would regard this as not part of the table/view spec but should rather be included in the REST catalog specification.

JanKaul and others added 20 commits October 15, 2026 08:29
Co-authored-by: Daniel Weeks <daniel.weeks@databricks.com>
- Define freshness as a universal property: storage table equals the
  result of the current view query (at the MV's current view-version-id)
  over the current state of dependencies.
- Define dependencies objectively by parsing the SQL: base tables, views
  (transitively expanded), and intermediate materialized views (treated
  as their storage tables with recursive freshness via their own
  refresh-state). Drop the producer-relative dependency framing.
- Reorganize the freshness section into producer flexibility and
  consumer options. Producer chooses what to record; consumer chooses
  what to verify. Producer-first ordering matches the chronological flow.
- Tighten the schema: intermediate materialized views are recorded as a
  single table entry referencing the storage table; recording as a view
  entry is not permitted.
- Crisp read-decision rule: if a consumer's assessment passes, it reads
  from the storage table; otherwise it evaluates the view query in place
  of the storage table.
- Replace the "consumer/producer behavior" prose under Freshness with
  Producer flexibility and Consumer options subsections that match the
  three reference verification paths (recency policy, trust, verify).
- Add Appendix B "What counts as a dependency" with the SQL-derived
  dependency rules and a worked example showing the recursive boundary
  for intermediate materialized views.
Co-authored-by: Daniel Weeks <daniel.weeks@databricks.com>
Co-authored-by: Daniel Weeks <daniel.weeks@databricks.com>
- make source table snapshot-id optional (empty source tables)
- define ref semantics for branch/tag tracking vs pinned snapshots
- note storage-table field is backward compatible for MV-unaware readers
- fix C/D materialized view example and spec/typo nits
@JanKaul
JanKaul force-pushed the materialized-view-spec branch from f14886b to ba28913 Compare October 15, 2026 06:29
Comment thread format/view-spec.md
} ],
"storage-table" : {
"namespace" : [ "default" ],
"name" : "event_agg_mv__storage"

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.

it is worthwhile to point out explicitly in the text that it is the writer's responsibility to create the storage table event_agg_mv__storage.

Comment thread format/view-spec.md Outdated

### Strategy 2: Treat nested materialized views as tables

Same as Strategy 1, but the query reads from materialized views. The producer stops at each MV boundary and records the MV's storage table snapshot ID and view version ID. No expansion beyond the MV.

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.

the query reads from materialized views

the query reads from materialized views storage tables.

Comment thread format/view-spec.md Outdated

### Strategy 3: Treat nested materialized views as views

Same as Strategy 1, but the query reads from materialized views. The producer treats each materialized view as a regular view: expand through the MV's view definition and record the underlying tables and views. The MV's storage table snapshot ID is **not** recorded.

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.

but the query reads from materialized views

but the query expands recursively the view queries corresponding to the materialized views.

Generated-by: Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread format/view-spec.md
| _optional_ | `snapshot-id` | The snapshot-id of the source table that was read during the refresh operation. Omitted when the source table had no snapshots at refresh time (e.g. a newly created, empty table) |
| _optional_ | `ref` | Branch name of the source table being referenced in the view query |

When `ref` is set, the source table is tracked against that branch or tag, and the materialized view is stale once the ref advances past the recorded `snapshot-id`. When `ref` is not set, the source table is pinned to the recorded `snapshot-id` (e.g. `FOR VERSION AS OF <snapshot-id>`); the materialized view remains fresh with respect to this source as long as that snapshot exists. Producers that read a branch should record the branch name in `ref`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the materialized view remains fresh with respect to this source as long as that snapshot exists.

I think this is overly strong statement. It again tries to define "freshness".

Comment thread format/view-spec.md Outdated

### Strategy 5: Skip non-Iceberg dependencies

The producer records only Iceberg sources and omits non-Iceberg dependencies entirely. Useful when the view query reads from a mix of Iceberg and non-Iceberg sources and the producer chooses to track only the Iceberg side.

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.

producer -> writer

@JanKaul
JanKaul force-pushed the materialized-view-spec branch from f1ef761 to 75cb171 Compare October 29, 2026 19:26

This branch has not been deployed

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

Labels

not-stale Specification Issues that may introduce spec changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.