pvary commented on code in PR #14933:
URL: https://github.com/apache/iceberg/pull/14933#discussion_r2675724549
##########
spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/actions/TestSnapshotTableAction.java:
##########
@@ -65,4 +70,66 @@ public void testSnapshotWithParallelTasks() throws
IOException {
.execute();
assertThat(snapshotThreadsIndex.get()).isEqualTo(2);
}
+
+ @TestTemplate
+ public void testSnapshotWithOverlappingLocation() throws IOException {
+ String catalogType = catalogConfig.get(ICEBERG_CATALOG_TYPE);
+ assumeThat(catalogType).isNotEqualTo(ICEBERG_CATALOG_TYPE_HADOOP);
+
+ String sourceLocation =
+ Files.createTempDirectory(temp,
"junit").resolve("source").toFile().toString();
+ sql(
+ "CREATE TABLE %s (id bigint NOT NULL, data string) USING parquet
LOCATION '%s'",
+ SOURCE_NAME, sourceLocation);
+ sql("INSERT INTO TABLE %s VALUES (1, 'a')", SOURCE_NAME);
+ sql("INSERT INTO TABLE %s VALUES (2, 'b')", SOURCE_NAME);
+ String actualSourceLocation =
+ spark
+ .sql(String.format("DESCRIBE EXTENDED %s", SOURCE_NAME))
+ .filter("col_name = 'Location'")
+ .select("data_type")
+ .first()
+ .getString(0);
+
+ assertThatThrownBy(
+ () ->
+ SparkActions.get()
+ .snapshotTable(SOURCE_NAME)
+ .as(tableName)
+ .tableLocation(actualSourceLocation)
+ .execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageStartingWith(
+ "The snapshot table location cannot be same as the source table
location.");
+
+ String destAsSubdirectory = new Path(actualSourceLocation,
"nested").toUri().toString();
+ assertThatThrownBy(
+ () ->
+ SparkActions.get()
+ .snapshotTable(SOURCE_NAME)
+ .as(tableName)
+ .tableLocation(destAsSubdirectory)
+ .execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageStartingWith("Cannot create a snapshot at location");
+
+ String parentLocation = new
Path(actualSourceLocation).getParent().toUri().toString();
+ assertThatThrownBy(
+ () ->
+ SparkActions.get()
+ .snapshotTable(SOURCE_NAME)
+ .as(tableName)
+ .tableLocation(parentLocation)
+ .execute())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageStartingWith("Cannot create a snapshot at location");
+
+ String validDestLocation = new Path(parentLocation,
"newDestination").toUri().toString();
+ SparkActions.get()
+ .snapshotTable(SOURCE_NAME)
+ .as(tableName)
+ .tableLocation(validDestLocation)
+ .execute();
+ assertThat(sql("SELECT * FROM %s", tableName)).hasSize(2);
Review Comment:
Do we need this test here?
Should this be a different test case for the happy path?
--
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]