nastra commented on code in PR #9878: URL: https://github.com/apache/iceberg/pull/9878#discussion_r1514339962
########## docs/docs/spark-ddl.md: ########## @@ -566,3 +566,85 @@ Tags can be removed via the `DROP TAG` sql ```sql ALTER TABLE prod.db.sample DROP TAG `historical-tag` ``` + +### Iceberg Views in Spark + +#### Creating a View +Creating a view in its simplest form can be done as shown below: +```sql +CREATE VIEW <viewName> AS SELECT * from <tableName> +``` + +Using `IF NOT EXISTS` prevents the SQL from failing in case the view already exists: +```sql +CREATE VIEW IF NOT EXISTS <viewName> AS SELECT * from <tableName> +``` + +It is also possible to use a modified schema for the view, where each column has an alias that is different from the source table and carries a comment. +Additionally, the view itself can have a comment as can be seen below: +```sql +CREATE VIEW <viewName> (ID COMMENT 'Unique ID', ZIP COMMENT 'Zipcode') + COMMENT 'View Comment' + AS SELECT id, zip FROM <tableName> +``` + +#### Creating a View with Properties + +A view can be created with properties by using `TBLPROPERTIES`: +```sql +CREATE VIEW <viewName> + TBLPROPERTIES ('key1' = 'val1', 'key2' = 'val2') + AS SELECT * from <tableName> +``` + +These properties can be displayed using: +```sql +SHOW TBLPROPERTIES <viewName> +``` + +#### Replacing a View + +Updating a view's schema, its properties, or the underlying SQL can be achieved as shown below: +```sql +CREATE OR REPLACE <viewName> (updated_id COMMENT 'updated ID') + TBLPROPERTIES ('key1' = 'new_val1') + AS SELECT id FROM <tableName> +``` + +#### Setting/removing View properties + +Properties can be set via the following SQL: +```sql +ALTER VIEW <viewName> SET TBLPROPERTIES ('key1' = 'val1', 'key2' = 'val2') +``` + +Properties can be removed using: +```sql +ALTER VIEW <viewName> UNSET TBLPROPERTIES ('key1') +``` + +#### Showing available Views + +The below SQL will list all views in the currently set namespace: +```sql +SHOW VIEWS +``` + +The below SQL will list all available views in the defined catalog/namespace +```sql +SHOW VIEWS IN <catalog|namespace> +``` + +#### Showing the CREATE stmt of a View + +```sql +SHOW CREATE TABLE <viewName> Review Comment: yes that's the official Spark syntax -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org