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



##########
File path: site/docs/row-level-deletes.md
##########
@@ -0,0 +1,196 @@
+<!--
+ - 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.
+ -->
+
+# Row-Level Deletes
+
+Iceberg supports metadata-based deletion through the `DeleteFiles` interface.
+It allows you to quickly delete a specific file or any file that might match a 
given expression without the need to read or write any data in the table.
+
+Row-level delete targets more complicated use cases such as general data 
protection regulation (GDPR).
+Copy-on-write and merge-on-read are two different approaches to handle 
row-level delete operations. Here are their definitions in Iceberg:
+
+- **copy-on-write**: a delete directly rewrites all the affected data files.
+- **merge-on-read**: delete information is encoded in the form of _delete 
files_. The table reader can apply all delete information at read time.
+
+Overall, copy-on-write is more efficient in reading data, whereas 
merge-on-read is more efficient in writing deletes, but requires more 
maintenance and tuning to be performant in reading data with deletes.
+Users can choose to use **both** copy-on-write and merge-on-read for the same 
Iceberg table based on different situations. 
+For example, a time-partitioned table can have newer partitions with more 
frequent updates maintained in the merge-on-read approach through a streaming 
pipeline,
+and older partitions maintained in the copy-on-write approach with less 
frequent GDPR deletes from batch ETL jobs.
+
+There are use cases that could only be supported by one approach such as 
change data capture (CDC).
+There are also limitations for different compute engines that lead them to 
prefer one approach over another.
+Please check out the documentation of the specific compute engines to see the 
details of their capabilities for these two approaches.
+In this article, we will focus on explaining Iceberg's core design of 
copy-on-write and merge-on-read.
+
+!!!Note
+    In Iceberg, update is modeled as a delete with an insert within the same 
transaction. 
+    Therefore, we will focus our discussion on delete in this article. 
+
+## Copy-on-write
+
+In the copy-on-write approach, given a user's delete requirement, the write 
process would search for all the affected data files and perform a rewrite 
operation.
+
+For example, consider an unpartitioned table with schema `(id bigint, category 
string, data string)` that has the following files:
+
+```
+file A: (1, 'c1', 'data1'), (2, 'c1', 'data2')
+file B: (3, 'c2', 'data1'), (4, 'c2', 'data2')
+file C: (5, 'c3', 'data3'), (6, 'c3', 'data2')
+```
+
+A copy-on-write deletion of `data='data1'` rewrites files A and B into a 
different set of files. An example output table file layout might look like:
+
+```
+file D: (2, 'c1', 'data2'), (4, 'c2', 'data2')
+file C: (5, 'c3', 'data3'), (6, 'c3', 'data2')
+```
+
+There is no effect on read side in the copy-on-write approach.
+
+## Merge-on-read
+
+### Row-level delete file spec
+
+Iceberg supports 2 different types of row-level delete files: **position 
deletes** and **equality deletes**.
+If you are unfamiliar with these concepts, please read the 
[spec](../spec/#row-level-deletes) page for more information before proceeding.
+
+Also note that because row-level delete files are valid Iceberg data files, 
all rows in each delete file must belong to the same partition.
+If a delete file belongs to `Unpartitioned` (the partition spec has no 
partition field), then the delete file is called a **global delete**. 
+Otherwise, it is called a **partition delete**.
+
+### Writing delete files
+
+From the end user's perspective, it is very rare to directly request deletion 
of a specific row of a specific file. 
+A delete requirement usually comes as a predicate such as `id = 5` or `date < 
TIMESTAMP '2000-01-01'`. 
+Given a predicate, delete files can be produced in one or some combinations of 
the following ways:
+
+1. **partition position deletes**: perform a scan \[1\] to know the data files 
and row positions affected by the predicate and then write partition position 
deletes \[2\]
+2. **partition equality deletes**: convert input predicate to equality 
predicates \[3\] for each affected partition and write partition equality 
deletes
+3. **partition global deletes**: convert input predicate to equality 
predicates and write global equality deletes 

Review comment:
       sorry my typo, it's "global equality deletes".
   
   I think what I mean here for partition and global is from the perspective of 
partitioned table. For unpartitioned table, partition delete is "global" 
anyway. I will make it more clear.




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