nevzheng commented on code in PR #11041:
URL: https://github.com/apache/iceberg/pull/11041#discussion_r3565656001


##########
format/view-spec.md:
##########
@@ -42,12 +42,27 @@ An atomic swap of one view metadata file for another 
provides the basis for maki
 
 Writers create view metadata files optimistically, assuming that the current 
metadata location will not be changed before the writer's commit. Once a writer 
has created an update, it commits by swapping the view's metadata file pointer 
from the base location to the new location.
 
+### Materialized Views
+
+Materialized views are a type of view with precomputed results from the view 
query stored as a table.
+When queried, engines may return the precomputed data for the materialized 
views, shifting the cost of query execution to the precomputation step.
+
+Iceberg materialized views are implemented as a combination of an Iceberg view 
and an underlying Iceberg table, the "storage-table", which stores the 
precomputed data.
+Materialized View metadata is a superset of View metadata with an additional 
pointer to the storage table. The storage table is an Iceberg table with 
additional materialized view refresh state metadata.
+Refresh metadata contains information about the "source tables", "source 
views", and/or "source materialized views", which are the 
tables/views/materialized views used in the computation of the query results of 
the materialized view.
+
 ## Specification
 
 ### Terms
 
 * **Schema** -- Names and types of fields in a view.
 * **Version** -- The state of a view at some point in time.
+* **Storage table** -- Iceberg table that stores the precomputed data of a 
materialized view.
+* **Refresh state** -- A record stored in the storage table's snapshot summary 
that captures the state of source tables and views at the time of the last 
refresh operation.
+* **Dependency graph** -- The graph of all source tables, views, and 
materialized views that a materialized view depends on, including nested 
dependencies.
+* **Source table** -- A table reference that is used in the computation of the 
query results of a materialized view.
+* **Source view** -- A view reference that is used in the computation of the 
query results of a materialized view.
+* **Source materialized view** -- A materialized view reference that is used 
in the computation of the query results of a materialized view.

Review Comment:
   +1. 
   I'm in favor of being concise. We can fold this into the sections below.



##########
format/view-spec.md:
##########
@@ -160,7 +178,116 @@ Each entry in `version-log` is a struct with the 
following fields:
 | _required_  | `timestamp-ms` | Timestamp when the view's 
`current-version-id` was updated (ms from epoch) |
 | _required_  | `version-id`   | ID that `current-version-id` was set to |
 
-## Appendix A: An Example
+#### Storage Table Identifier
+
+The table identifier for the storage table that stores the precomputed results.
+
+| Requirement | Field name     | Description |
+|-------------|----------------|-------------|
+| _required_  | `namespace`    | A list of strings for namespace levels |
+| _required_  | `name`         | A string specifying the name of the table |
+
+### Storage table metadata
+
+This section describes additional metadata for the storage table that 
supplements the regular table metadata and is required for materialized views.
+The `refresh-state` property is set on the [snapshot 
summary](https://iceberg.apache.org/spec/#snapshots) property of a storage 
table snapshot to provide information about the state of the precomputed data.
+
+| Requirement | Field name      | Description |
+|-------------|-----------------|-------------|
+| _optional_  | `refresh-state` | A [refresh state](#refresh-state) record 
stored as a JSON-encoded string |
+
+#### Freshness
+
+A materialized view is **fresh** when the storage table represents the result 
of the current view query. However, consumers may still decide to consume from 
a stale storage table based on their own policies.
+
+A change to the materialized view's definition produces a new 
`view-version-id`; any storage-table snapshot recorded at a prior 
`view-version-id` is invalid and should not be consumed until refreshed.
+
+#### Refresh state
+
+The refresh state record captures the state of dependencies that the producer 
chose to track from the materialized view's dependency graph. A dependency is 
recorded in `source-states` as either a `table` entry (a source table or an 
source materialized view's storage table) and/or a `view` entry. Source 
materialized views can be stored as a `view` and a `table` entry.
+
+The refresh state has the following fields:
+
+| Requirement | Field name                   | Description |
+|-------------|------------------------------|-------------|
+| _required_  | `view-version-id`            | The `version-id` of the 
materialized view when the refresh operation was performed |
+| _required_  | `source-states`              | A list of [source 
state](#source-state) records capturing the dependencies the producer chose to 
track; may be empty |
+| _required_  | `refresh-start-timestamp-ms` | A timestamp of when the refresh 
operation was started |
+
+##### Producer: Recording Refresh State
+
+Producers may selectively choose a subset of their dependencies to record — 
for example, skipping non-Iceberg sources or recording an empty list. See 
[Appendix B](#appendix-b-what-counts-as-a-dependency) for strategies on how to 
store dependency state.
+
+When writing the refresh state, producers:
+
+- **Must** record `view-version-id` and `refresh-start-timestamp-ms`.
+- **Should** include all distinct source states for the inputs they chose to 
track if they are reachable through multiple path in the dependency graph.
+- **May** leave `source-states` empty (e.g., when sources are non-Iceberg or 
freshness is determined by a mechanism outside this spec).
+
+##### Consumer: Evaluating Refresh State
+
+Consumers may use any combination of the following to assess the state of 
dependencies used to produce the storage table.
+
+- **Recency policy.** Accept the storage table when 
`refresh-start-timestamp-ms` falls within a staleness window. A recency policy 
bounds data age but does not establish freshness.
+- **Trust the recorded `source-states`.** Compare each entry against the 
current catalog state — `snapshot-id` for tables, `version-id` for views, 
optionally recursive verification for source materialized views recorded by 
their storage tables. Also confirm that the recorded `view-version-id` equals 
the materialized view's current `view-version-id`.
+- **Verify by parsing the view query.** Derive the dependency set from the SQL 
and confirm every dependency is covered by `source-states` and matches the 
current state. Treat any uncovered dependency as undetermined.
+
+If a consumer's assessment passes, it reads from the storage table. If not, 
the consumer may fail the query, evaluate the view query directly, or apply 
another strategy.
+
+#### Source state
+
+Source state records capture the state of objects referenced by a materialized 
view. Each record has a `type` field that determines its form:
+
+| Type    | Description |
+|---------|-------------|
+| `table` | An Iceberg table — either a source table in the dependency graph, 
or the storage table of a source materialized view |

Review Comment:
   If table can be a BASE table or a STORAGE table, how are we distinguishing 
between the two?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to