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


##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/actions/TestSnapshotTableAction.java:
##########
@@ -65,4 +68,81 @@ public void testSnapshotWithParallelTasks() throws 
IOException {
         .execute();
     assertThat(snapshotThreadsIndex.get()).isEqualTo(2);
   }
+
+  @TestTemplate
+  public void testTableLocationOverlapThrowsException() throws IOException {
+    // Ensure the test runs only for non-Hadoop-based catalogs,
+    // because path-based tables cannot have a custom location set.
+    assumeThat(catalogName)
+        .as("Cannot set a custom location for a path-based table.")
+        .isNotEqualTo("testhadoop");
+
+    String location = Files.createTempDirectory(temp, 
"junit").toFile().toURI().toString();
+
+    sql(
+        "CREATE TABLE %s (id bigint NOT NULL, data string) USING parquet 
LOCATION '%s'",
+        SOURCE_NAME, location);
+    sql("INSERT INTO TABLE %s VALUES (1, 'a')", SOURCE_NAME);
+    sql("INSERT INTO TABLE %s VALUES (2, 'b')", SOURCE_NAME);
+
+    // Define properties for the destination table, setting its location to 
the same path as the
+    // source table
+    Map<String, String> tableProperties = Map.of("location", location);
+
+    assertThatThrownBy(
+            () ->
+                SparkActions.get()
+                    .snapshotTable(SOURCE_NAME)
+                    .as(tableName)
+                    .tableProperties(tableProperties)
+                    .execute())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining(
+            "The destination table location overlaps with the source table 
location");
+
+    // Test for path with and without trailing slash (should be considered the 
same)
+    String locationWithSlash = location.endsWith("/") ? location : location + 
"/";
+    Map<String, String> tablePropertiesWithSlash = Map.of("location", 
locationWithSlash);
+
+    assertThatThrownBy(
+            () ->
+                SparkActions.get()
+                    .snapshotTable(SOURCE_NAME)
+                    .as(tableName)
+                    .tableProperties(tablePropertiesWithSlash)
+                    .execute())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining(
+            "The destination table location overlaps with the source table 
location");
+
+    // Test for nested paths (source and destination are subdirectories of 
each other)
+    String nestedLocation = location + "/nested";
+    Map<String, String> tablePropertiesWithNested = Map.of("location", 
nestedLocation);
+
+    assertThatThrownBy(
+            () ->
+                SparkActions.get()
+                    .snapshotTable(SOURCE_NAME)
+                    .as(tableName)
+                    .tableProperties(tablePropertiesWithNested)
+                    .execute())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining(
+            "The destination table location overlaps with the source table 
location");
+
+    // Test for relative path with ".." (parent directory reference)
+    String locationWithParent = location + "/.."; // Points to the same 
directory as location

Review Comment:
   nit: do you mean `// Points to the parent directory as 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