ebyhr commented on code in PR #12779: URL: https://github.com/apache/iceberg/pull/12779#discussion_r2048176417
########## spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/actions/SnapshotTableSparkAction.java: ########## @@ -124,10 +124,12 @@ private SnapshotTable.Result doExecute() { StagedSparkTable stagedTable = stageDestTable(); Table icebergTable = stagedTable.table(); - // TODO: Check the dest table location does not overlap with the source table location - boolean threw = true; try { + Preconditions.checkArgument( + !sourceTableLocation().equals(icebergTable.location()), + "The destination table location overlaps with the source table location."); Review Comment: The following `.` can be removed. Most existing error messages don't end with `.` unless they have several sentences. ########## spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/actions/TestSnapshotTableAction.java: ########## @@ -65,4 +69,40 @@ 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().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 = Maps.newHashMap(); + tableProperties.put("location", "file:" + location); + + // Test that an exception is thrown + // when the destination table location overlaps with the source table location + // Assert that the exception message matches the expected error message Review Comment: > Assert that the exception message matches the expected error message I would remove this comment. This is obvious when reading the following code. ########## spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/actions/TestSnapshotTableAction.java: ########## @@ -65,4 +69,40 @@ 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().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 = Maps.newHashMap(); + tableProperties.put("location", "file:" + location); Review Comment: We make it single line: ```java Map<String, String> tableProperties = Map.of("location", "file:" + 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org