osscm commented on code in PR #11041: URL: https://github.com/apache/iceberg/pull/11041#discussion_r4098811303
########## format/view-spec.md: ########## @@ -160,7 +180,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 paths 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`. Review Comment: Following up on this since it doesn't look like it made it into the spec text yet (I don't see anything about snapshot expiration/retention under source-table-state) - apologies if this was actually settled elsewhere and I missed it. The scenario I keep getting stuck on: once a source table's retention/expiration policy removes the snapshot that was recorded in source-table-state.snapshot-id, the recorded reference just points at nothing anymore. At that point there's no way to compare "recorded snapshot" vs. "current snapshot" to decide whether the source actually changed - the comparison itself becomes undefined, not just "stale." Is the intent that a missing/expired snapshot reference should always be treated as stale (safe, but can trigger unnecessary full refreshes on any table with a live expiration policy), or is there some other fallback in mind - e.g. keying off something more durable than the raw snapshot-id (the sequence-number idea mentioned earlier in this thread), or expecting producers to defensively re-record before expiration happens? Trying to understand whether "reference no longer resolves" is meant to be a distinct case from "reference resolves but doesn't match," or if I'm overthinking this. cc @JanKaul @wmoustafa -- 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]
