amogh-jahagirdar commented on code in PR #6723:
URL: https://github.com/apache/iceberg/pull/6723#discussion_r1173181796


##########
docs/branching-and-tagging.md:
##########
@@ -0,0 +1,116 @@
+---
+title: "Branching and Tagging"
+url: branching
+aliases:
+    - "tables/branching"
+menu:
+    main:
+        parent: Tables
+        weight: 0
+---
+
+<!--
+ - 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.
+ -->
+
+# Branching and Tagging
+
+## Overview
+
+Iceberg table metadata maintains a log of snapshots which represent the 
changes applied to a table.
+Snapshots are fundamental in Iceberg as they are the basis for reader 
isolation and time travel queries.
+For controlling metadata size and storage costs, Iceberg provides snapshot 
lifecycle management procedures such as 
[`expire_snapshots`](../../spark/spark-procedures/#expire-snapshots) for 
removing unused snapshots and no longer neccessary data files based on table 
snapshot retention properties.
+
+**For more sophisticated snapshot lifecycle management, Iceberg supports 
branches and tags which are named references to snapshots with their own 
independent lifecycles. This lifecycle is controlled by branch and tag level 
retention policies.** 
+Branches are independent lineages of snapshots and point to the head of the 
lineage. 
+Branches and tags have a maximum reference age property which control when the 
reference to the snapshot itself should be expired.
+Branches have retention properties which define the minimum number of 
snapshots to retain on a branch as well as the maximum age of individual 
snapshots to retain on the branch. 
+These properties are used when the expireSnapshots procedure is run. 
+For details on the algorithm for expireSnapshots, refer to the 
[spec](../../../spec#snapshot-retention-policy).
+
+## Use Cases
+
+Branching and tagging can be used for handling GDPR requirements and retaining 
important historical snapshots for auditing.
+Branches can also be used as part of data engineering workflows, for enabling 
experimental branches for testing and validating new jobs.
+See below for some examples of how branching and tagging can facilitate these 
use cases.
+
+### Historical Tags
+
+Tags can be used for retaining important historical snapshots for auditing 
purposes.
+
+![Historical Tags](../img/historical-snapshot-tag.png)
+
+The above diagram demonstrates retaininig important historical snapshot with 
the following retention policy, defined 
+via Spark SQL.
+
+1. Retain the latest 5 days of snapshots for 1 week. This can be achieved by 
setting a branch retention policy where 5 days worth of snapshots will be kept, 
and the branch reference itself will be retained for 1 week. 
+```sql
+-- Create a branch historical-branch which will all snapshots be written to. 
Historical-branch will be retained for 7 days, and 5 days worth of snapshots 
will be retained
+ALTER TABLE prod.db.table CREATE BRANCH historical-branch AS OF VERSION 1 
RETAIN 7 DAYS WITH RETENTION 5 DAYS
+```
+
+2. Retain 1 snapshot per week for 1 month. This can be achieved by tagging the 
weekly snapshot and setting the tag retention to be a month.
+snapshots will be kept, and the branch reference itself will be retained for 1 
week. 
+```sql
+-- Create a tag for the first end of week snapshot. Retain the snapshot for a 
week
+ALTER TABLE prod.db.table CREATE TAG 'EOW-01' AS OF VERSION 7 RETAIN 7 DAYS
+```
+
+3. Retain 1 snapshot per month for 6 months. This can be achieved by tagging 
the monthly snapshot and setting the tag retention to be 6 months.
+```sql
+-- Create a tag for the first end of month snapshot. Retain the snapshot for 6 
months
+ALTER TABLE prod.db.table CREATE TAG 'EOM-01' AS OF VERSION 30 RETAIN 180 DAYS
+```
+
+4. Retain 1 snapshot per year forever. This can be achieved by tagging the 
annual snapshot. The default retention for branches and tags is forever.
+```sql
+-- Create a tag for the end of the year and retain it forever.
+ALTER TABLE prod.db.table CREATE TAG 'EOY-2023' AS OF VERSION 365
+```
+
+### Audit Branch
+
+![Audit Branch](../img/audit-branch.png)
+
+The above diagram shows an example of using an audit branch for validating a 
write workflow. 
+
+1. Create `audit-branch` starting from snapshot 3, which will be written to 
and retained for 1 week.
+```sql
+ALTER TABLE db.table CREATE BRANCH `audit-branch` AS OF VERSION 3 RETAIN 7 DAYS

Review Comment:
   good catch, yeah I included that as step 1.



##########
docs/branching-and-tagging.md:
##########
@@ -0,0 +1,116 @@
+---
+title: "Branching and Tagging"
+url: branching
+aliases:
+    - "tables/branching"
+menu:
+    main:
+        parent: Tables
+        weight: 0
+---
+
+<!--
+ - 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.
+ -->
+
+# Branching and Tagging
+
+## Overview
+
+Iceberg table metadata maintains a log of snapshots which represent the 
changes applied to a table.
+Snapshots are fundamental in Iceberg as they are the basis for reader 
isolation and time travel queries.
+For controlling metadata size and storage costs, Iceberg provides snapshot 
lifecycle management procedures such as 
[`expire_snapshots`](../../spark/spark-procedures/#expire-snapshots) for 
removing unused snapshots and no longer neccessary data files based on table 
snapshot retention properties.
+
+**For more sophisticated snapshot lifecycle management, Iceberg supports 
branches and tags which are named references to snapshots with their own 
independent lifecycles. This lifecycle is controlled by branch and tag level 
retention policies.** 
+Branches are independent lineages of snapshots and point to the head of the 
lineage. 
+Branches and tags have a maximum reference age property which control when the 
reference to the snapshot itself should be expired.
+Branches have retention properties which define the minimum number of 
snapshots to retain on a branch as well as the maximum age of individual 
snapshots to retain on the branch. 
+These properties are used when the expireSnapshots procedure is run. 
+For details on the algorithm for expireSnapshots, refer to the 
[spec](../../../spec#snapshot-retention-policy).
+
+## Use Cases
+
+Branching and tagging can be used for handling GDPR requirements and retaining 
important historical snapshots for auditing.
+Branches can also be used as part of data engineering workflows, for enabling 
experimental branches for testing and validating new jobs.
+See below for some examples of how branching and tagging can facilitate these 
use cases.
+
+### Historical Tags
+
+Tags can be used for retaining important historical snapshots for auditing 
purposes.
+
+![Historical Tags](../img/historical-snapshot-tag.png)
+
+The above diagram demonstrates retaininig important historical snapshot with 
the following retention policy, defined 
+via Spark SQL.
+
+1. Retain the latest 5 days of snapshots for 1 week. This can be achieved by 
setting a branch retention policy where 5 days worth of snapshots will be kept, 
and the branch reference itself will be retained for 1 week. 
+```sql
+-- Create a branch historical-branch which will all snapshots be written to. 
Historical-branch will be retained for 7 days, and 5 days worth of snapshots 
will be retained
+ALTER TABLE prod.db.table CREATE BRANCH historical-branch AS OF VERSION 1 
RETAIN 7 DAYS WITH RETENTION 5 DAYS
+```
+
+2. Retain 1 snapshot per week for 1 month. This can be achieved by tagging the 
weekly snapshot and setting the tag retention to be a month.
+snapshots will be kept, and the branch reference itself will be retained for 1 
week. 
+```sql
+-- Create a tag for the first end of week snapshot. Retain the snapshot for a 
week
+ALTER TABLE prod.db.table CREATE TAG 'EOW-01' AS OF VERSION 7 RETAIN 7 DAYS
+```
+
+3. Retain 1 snapshot per month for 6 months. This can be achieved by tagging 
the monthly snapshot and setting the tag retention to be 6 months.
+```sql
+-- Create a tag for the first end of month snapshot. Retain the snapshot for 6 
months
+ALTER TABLE prod.db.table CREATE TAG 'EOM-01' AS OF VERSION 30 RETAIN 180 DAYS
+```
+
+4. Retain 1 snapshot per year forever. This can be achieved by tagging the 
annual snapshot. The default retention for branches and tags is forever.
+```sql
+-- Create a tag for the end of the year and retain it forever.
+ALTER TABLE prod.db.table CREATE TAG 'EOY-2023' AS OF VERSION 365
+```
+
+### Audit Branch
+
+![Audit Branch](../img/audit-branch.png)
+
+The above diagram shows an example of using an audit branch for validating a 
write workflow. 
+
+1. Create `audit-branch` starting from snapshot 3, which will be written to 
and retained for 1 week.
+```sql
+ALTER TABLE db.table CREATE BRANCH `audit-branch` AS OF VERSION 3 RETAIN 7 DAYS

Review Comment:
   good catch, yeah I defined that now as step 1.



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