nastra commented on code in PR #9878: URL: https://github.com/apache/iceberg/pull/9878#discussion_r1514341452
########## 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> +``` Review Comment: this is describing SQL-level examples where you can't specify the dialect as it's controlled by the engine that executes the SQL -- 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