aokolnychyi commented on a change in pull request #351: Extend Iceberg with a 
way to overwrite files for eager updates/deletes
URL: https://github.com/apache/incubator-iceberg/pull/351#discussion_r314233769
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/OverwriteData.java
 ##########
 @@ -88,6 +121,40 @@ public OverwriteFiles validateAddedFiles() {
       }
     }
 
+    if (conflictingAppendsRowFilter != null) {
+      PartitionSpec spec = writeSpec();
+      Expression inclusiveExpr = 
Projections.inclusive(spec).project(conflictingAppendsRowFilter);
+      Evaluator inclusive = new Evaluator(spec.partitionType(), inclusiveExpr);
+
+      List<DataFile> newFiles = collectNewFiles(base);
+      for (DataFile newFile : newFiles) {
+        // we do partition-level conflict resolution right now
+        // we can enhance it by leveraging column stats and MetricsEvaluator
+        ValidationException.check(
+            !inclusive.eval(newFile.partition()),
+            "A conflicting file was appended that matches filter '%s': %s",
+            conflictingAppendsRowFilter, newFile.path());
+      }
+    }
+
     return super.apply(base);
   }
+
+  private List<DataFile> collectNewFiles(TableMetadata meta) {
+    List<DataFile> newFiles = new ArrayList<>();
+
+    Long currentSnapshotId = meta.currentSnapshot() == null ? null : 
meta.currentSnapshot().snapshotId();
+    while (currentSnapshotId != null && 
!currentSnapshotId.equals(readSnapshotId)) {
+      Snapshot currentSnapshot = meta.snapshot(currentSnapshotId);
+
+      if (currentSnapshot == null) {
+        throw new ValidationException("Cannot find snapshot %d. Was it 
expired?", currentSnapshotId);
 
 Review comment:
   I think `meta.currentSnapshot` can be `null` if the overwrite happens on an 
empty table. In that case, the read snapshot is also `null`, so it should work 
correctly. We have a test for this as well. Such a situation might happen if we 
use this API for eager `MERGE INTO` operations.
   
   Will update the error message.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to