huaxingao commented on code in PR #13962:
URL: https://github.com/apache/iceberg/pull/13962#discussion_r2317342861


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/SnapshotTableSparkAction.java:
##########
@@ -222,4 +224,22 @@ public SnapshotTableSparkAction tableLocation(String 
location) {
     this.destTableLocation = location;
     return this;
   }
+
+  private void checkLocationOverlap(String sourceTableLocation, String 
icebergTableLocation) {
+    String normalizedSourceLocation = normalizePath(sourceTableLocation);
+    String normalizedIcebergLocation = normalizePath(icebergTableLocation);
+
+    Preconditions.checkArgument(
+        !normalizedIcebergLocation.startsWith(normalizedSourceLocation),
+        "The destination table location overlaps with the source table 
location");
+
+    String sourceParentLocation = new 
File(normalizedSourceLocation).getParent();
+    Preconditions.checkArgument(
+        !normalizedIcebergLocation.equals(normalizePath(sourceParentLocation)),
+        "The destination table location overlaps with the source table's 
parent directory");
+  }

Review Comment:
   How about 
   ```
   private void checkLocationOverlap(String sourceTableLocation, String 
icebergTableLocation) {
     Path src = Paths.get(sourceTableLocation).toAbsolutePath().normalize();
     Path dst = Paths.get(icebergTableLocation).toAbsolutePath().normalize();
   
     // Reject if either path is a prefix of the other (equal, ancestor, or 
descendant)
     Preconditions.checkArgument(
         !(dst.startsWith(src) || src.startsWith(dst)),
         "The destination table location overlaps with the source table 
location");
   }
   ```



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