rdblue commented on code in PR #3188:
URL: https://github.com/apache/iceberg/pull/3188#discussion_r841296057


##########
format/view-spec.md:
##########
@@ -0,0 +1,264 @@
+<!--
+ - Licensed to the Apache Software Foundation (ASF) under one or more
+ - contributor license agreements.  See the NOTICE file distributed with
+ - this work for additional information regarding copyright ownership.
+ - The ASF licenses this file to You under the Apache License, Version 2.0
+ - (the "License"); you may not use this file except in compliance with
+ - the License.  You may obtain a copy of the License at
+ -
+ -   http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing, software
+ - distributed under the License is distributed on an "AS IS" BASIS,
+ - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ - See the License for the specific language governing permissions and
+ - limitations under the License.
+ -->
+
+# Iceberg View Spec
+
+## Background and Motivation
+
+Most compute engines (e.g. Trino and Apache Spark) support views. A view is a 
logical table that can be referenced by future queries. Views do not contain 
any data. Instead, the query stored by the view is executed every time the view 
is referenced by another query.
+
+Each compute engine stores the metadata of the view in its proprietary format 
in the metastore of choice. Thus, views created from one engine can not be read 
or altered easily from another engine even when engines share the metastore as 
well as the storage system. This document standardizes the view metadata for 
ease of sharing the views across engines.
+
+## Goals
+
+* A common metadata format for view metadata, similar to how Iceberg supports 
a common table format for tables.
+* The view metadata format specification
+  * Includes storage format as well as APIs to write/read the metadata.
+  * Supports versioning of views to track how a view evolved over time.
+
+## Overview
+
+View metadata storage mirrors how Iceberg table metadata is stored and 
retrieved. View metadata is maintained in metadata files. All changes to view 
state create a new view metadata file and completely replace the old metadata 
using an atomic swap. Like Iceberg tables, this atomic swap is delegated to the 
metastore that tracks tables and/or views by name. The view metadata file 
tracks the view schema, custom properties, current and past versions, as well 
as other metadata.
+Each metadata file is self-sufficient. It contains the history of the last few 
operations performed on the view and can be used to roll back the view to a 
previous version.
+
+### Metadata Location
+
+An atomic swap of one view metadata file for another provides the basis for 
making atomic changes. Readers use the version of the view that was current 
when they loaded the view metadata and are not affected by changes until they 
refresh and pick up a new metadata location.
+
+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.
+
+## Specification
+
+### Terms
+
+* **Schema** -- Names and types of fields in a view.
+* **Version** -- The state of a view at some point in time.
+
+### View Metadata
+
+The view version metadata file has the following fields:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | format-version | An integer version number for the view format. 
Currently, this must be 1. Implementations must throw an exception if the 
view's version is higher than the supported version. |
+| Required | location | The view's base location. This is used to determine 
where to store manifest files and view metadata files. |
+| Required | current-version-id | Current version of the view. Set to ‘1’ when 
the view is first created. |
+| Optional | properties | A string to string map of view properties. This is 
used for metadata such as "comment" and for settings that affect view 
maintenance. This is not intended to be used for arbitrary metadata. |
+| Required | versions | An array of structs describing the last known versions 
of the view. Controlled by the table property: “version.history.num-entries”. 
See section [Versions](#versions). |
+| Required | version-log | A list of timestamp and version ID pairs that 
encodes changes to the current version for the view. Each time the 
current-version-id is changed, a new entry should be added with the 
last-updated-ms and the new current-version-id. |
+| Optional | schemas | A list of schemas, the same as the ‘schemas’ field from 
Iceberg table spec. |
+| Optional | current-schema-id | ID of the current schema of the view |
+
+#### Versions
+
+Field "versions" is an array of structs with the following fields:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | version-id | Monotonically increasing id indicating the version 
of the view. Starts with 1. |
+| Required | timestamp-ms | Timestamp expressed in ms since epoch at which the 
version of the view was created. |
+| Required | summary | A string map summarizes the version changes, including 
`operation`, described in [Summary](#summary). |
+| Required | representations | A list of "representations" as described in 
[Representations](#representations). |
+
+#### Version Log
+
+Field “version-log” is an array of structs that describe when each version was 
considered "current". Creation time is different and is stored in each 
version's metadata. This allows you to reconstruct what someone would have seen 
at some point in time. If the view has been updated and rolled back, this will 
show it. The struct has the following fields:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | timestamp-ms | Tthe timestamp hen the referenced version was made 
the current version |
+| Required | version-id | Version id of the view  |
+
+#### Summary
+
+Field “summary” is a string map with the following keys. Only `operation` is 
required. Engines may store additional key-value pairs in this map.
+
+| Required/Optional | Key | Value |
+|-------------------|-----|-------|
+| Required | operation | A string value indicating the view operation that 
caused this metadata to be created. Allowed values are “create” and “replace”. |
+| Optional | engine-version | A string value indicating the version of the 
engine that performed the operation |
+
+#### Representations
+
+Each representation is stored as an object with only one common field "type".
+The rest of the fields are interpreted based on the type.
+There is only one type of representation defined in the spec.

Review Comment:
   I don't think this sentence is needed. Right now there's only one. But we 
want people to standardize these here.



-- 
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: dev-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to