jackye1995 commented on a change in pull request #3188:
URL: https://github.com/apache/iceberg/pull/3188#discussion_r805468389



##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 |

Review comment:
       to have some consistency with the table spec tables: 
https://github.com/apache/iceberg/blob/master/docs/common/format/spec.md?plain=1#L508,
 can we make some changes to the tables in the view spec:
   1. use v1 instead of `Required/Optional` has header
   2. make column size consistent for everything before description
   3. lower case and bold `_required_` or `_optional_` for required or optional 
values

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |

Review comment:
       Saying `The only valid choice is "sql"` might make people doubt the 
necessity of the field. What about saying `The format used to store this 
representation of the view, currently the only supported type is "sql"`

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the view metadata files |
+| Required | current-version-id | Current version of the view. Set to ‘1’ when 
the view is first created. |

Review comment:
       what do you mean by an empty view? A view without a SQL definition?

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |
+
+Here are the fields for "sql" representation type:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | It must be set to "sql" |

Review comment:
       we already say "The rest of the fields are interpreted by the type of 
representation." above, I think we don't need `type` again in this table?

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |
+
+Here are the fields for "sql" representation type:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | It must be set to "sql" |
+| Required | sql | A string representing SQL definition of the view as input |
+| Required | dialect | A string specifying the dialect of the ‘sql’ field 
above. Used by engines to perform necessary translations to the SQL dialect 
supported by the engine. |
+| Optional | session-catalog | A string that specifies the catalog of the user 
session when the view was created / replaced. Used to resolve the tables in the 
view definition. |

Review comment:
       `session-catalog` as the name does not sound very intuitive to me, as 
Ryan says the user might be using a different session when evaluating this 
view, and will still use the catalog defined here to get the referenced 
table/view information by name. What about `default-catalog`?

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |
+
+Here are the fields for "sql" representation type:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | It must be set to "sql" |
+| Required | sql | A string representing SQL definition of the view as input |
+| Required | dialect | A string specifying the dialect of the ‘sql’ field 
above. Used by engines to perform necessary translations to the SQL dialect 
supported by the engine. |
+| Optional | session-catalog | A string that specifies the catalog of the user 
session when the view was created / replaced. Used to resolve the tables in the 
view definition. |
+| Optional | session-namespace | An array of strings indicating namespace at 
the time view was created / replaced. Used similar to ‘session-catalog’ above. |
+| Optional | field-aliases | A list of strings of field aliases E.g. a list of 
alias_name info specified in the following create view statement. `CREATE VIEW 
v (alias_name COMMENT 'docs', alias_name2, ...) AS SELECT ...` |
+| Optional | field-docs | A list of strings of field comments E.g. a list of 
‘comment’ info specified in the following create view statement. `CREATE VIEW v 
(alias_name COMMENT 'docs', alias_name2, ...) AS SELECT ...` |
+
+“version-log” is an array of structs describing the log of the versions 
created. The struct has the following fields:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | timestamp-ms | Timestamp expressed as ms since epoch for when the 
version of the view indicated in version-id field below was created |
+| Required | version-id | Version id of the view |
+
+## Appendix A: An Example
+
+The JSON metadata file format is described using an example below.
+
+Imagine the following sequence of operations:
+
+* `CREATE TABLE base_tab(c1 int, c2 varchar);`
+* `INSERT INTO base_tab VALUES (1,’one’), (2,’two’);`
+* `CREATE VIEW common_view AS SELECT * FROM base_tab;`
+* `CREATE OR REPLACE VIEW common_view AS SELECT count(*) AS my_cnt FROM 
base_tab;`
+
+The metadata json file created at the end of step 3 looks as follows. The file 
path looks like:
+`s3://my_company/my/warehouse/anorwood.db/common_view`
+
+The path is intentionally similar to the path for iceberg tables and contains 
a ‘metadata’ directory. 
(`METASTORE_WAREHOUSE_DIR/<dbname>.db/<viewname>/metadata`)
+
+The metadata directory contains View Version Metadata files. The text after 
'=>' symbols describes the fields.
+```

Review comment:
       Quite a few places are not up-to-date, I suppose you will fix later?

##########
File path: site/docs/spec.md
##########
@@ -357,6 +357,7 @@ A manifest file must store the partition spec and other 
metadata as properties i
 | _required_ | _required_ | `partition-spec`    | JSON fields representation 
of the partition spec used to write the manifest  |
 | _optional_ | _required_ | `partition-spec-id` | ID of the partition spec 
used to write the manifest as a string              |
 | _optional_ | _required_ | `format-version`    | Table format version number 
of the manifest as a string                      |
+| _optional_ | _optional_ | `object-type`       | Type of object this metadata 
file is for: "table" or "view". Default is "table". |

Review comment:
       would it be better to say `spec-type`? Not sure if it is only for me, 
but `object-type` sounds very Java

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.

Review comment:
       We already say "A view is a logical table" later, so we can save the 
first sentence to only say "most compute engines (e.g. Trino and Apache Spark) 
support views".

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |
+
+Here are the fields for "sql" representation type:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | It must be set to "sql" |
+| Required | sql | A string representing SQL definition of the view as input |
+| Required | dialect | A string specifying the dialect of the ‘sql’ field 
above. Used by engines to perform necessary translations to the SQL dialect 
supported by the engine. |
+| Optional | session-catalog | A string that specifies the catalog of the user 
session when the view was created / replaced. Used to resolve the tables in the 
view definition. |
+| Optional | session-namespace | An array of strings indicating namespace at 
the time view was created / replaced. Used similar to ‘session-catalog’ above. |
+| Optional | field-aliases | A list of strings of field aliases E.g. a list of 
alias_name info specified in the following create view statement. `CREATE VIEW 
v (alias_name COMMENT 'docs', alias_name2, ...) AS SELECT ...` |
+| Optional | field-docs | A list of strings of field comments E.g. a list of 
‘comment’ info specified in the following create view statement. `CREATE VIEW v 
(alias_name COMMENT 'docs', alias_name2, ...) AS SELECT ...` |

Review comment:
       why are field aliases not a part of `schemas`?

##########
File path: site/docs/view-spec.md
##########
@@ -0,0 +1,256 @@
+<!--
+ - 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 logical views, 
commonly known as ‘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. Views and 
tables occupy the same namespace.
+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
+
+The view metadata storage and retrieval mirrors how Iceberg table metadata is 
stored and retrieved. The view metadata is stored in a JSON file on object 
storage for ease of tracking the evolution of the view. Metastore continues to 
hold the view object with some properties such as database name, owner, create 
time, last access time and an indication that the object is a view.
+
+Each ‘CREATE OR REPLACE VIEW’ statement creates a new view version metadata 
file for that view.
+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
+
+The view metadata location is managed exactly like table metadata location.
+
+### Operations
+
+* Create a view
+* Drop the view
+* Load a view to read the metadata
+* Replace the view
+* Change the view definition
+* Add/delete/edit column comments
+
+## 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 | Json format version number for the view metadata 
spec. The view metadata spec and the corresponding format-version is 
independent of table spec. Starts with 1 and is incremented when there is a 
breaking change to view metadata. |
+| Required | object-type    | Type of object this metadata file is for: 
"table" or "view". It must be set to "view" for all objects covered in this 
spec. |
+| Required | location | Location of the 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. Contains 
pre-set properties such as ‘comment’ describing the view, does not contain 
arbitrary metadata. |
+| Required | versions | An array of structs describing the last few versions 
of the view. Controlled by the table property: “version.history.num_entries”. 
See more below. |
+| Required | version-log | An array of structs describing the log of created 
versions. See more below. |
+| 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’ is an array of structs with fields as shown below:
+
+| 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 to string map of view properties to track 
version metadata. This field can be used by engines to store any necessary 
properties. Two currently required properties are described below. |
+| Required | representations | A list of "representations" as described below. 
|
+
+
+Note that each version is stored in a separate AVRO file. This is to ensure 
that the metadata file stays readable in the case the view definition is huge. 
As a future extension, an engine-agnostic intermediate representation or a 
serialized abstract syntax tree of the SQL definition may also be stored in 
each version, exacerbating the problem.
+
+“summary” is a string-string map with the following required keys. 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 (create / replace) |
+
+“representations” is a list of structs with fields as shown below:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | A string indicating the type of representation. The only 
valid choice is "sql". The rest of the fields are interpreted by the type of 
representation. |
+
+Here are the fields for "sql" representation type:
+
+| Required/Optional | Field Name | Description |
+|-------------------|------------|-------------|
+| Required | type | It must be set to "sql" |
+| Required | sql | A string representing SQL definition of the view as input |
+| Required | dialect | A string specifying the dialect of the ‘sql’ field 
above. Used by engines to perform necessary translations to the SQL dialect 
supported by the engine. |
+| Optional | session-catalog | A string that specifies the catalog of the user 
session when the view was created / replaced. Used to resolve the tables in the 
view definition. |
+| Optional | session-namespace | An array of strings indicating namespace at 
the time view was created / replaced. Used similar to ‘session-catalog’ above. |

Review comment:
       "An array of strings indicating namespace" made me thought it was a list 
of namespaces until I then realized namespace is a list of string. I think 
people who don't have context would get confused here. I think it's more clear 
to say "Namespace to use when table or view references do not contain an 
explicit namespace", and then say `namespace is serialized as a list of string`.




-- 
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