Skip to content

Commit

Permalink
Add namespace validation for rename operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat committed Oct 20, 2023
1 parent c08e38d commit 8001a28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ public void testRefreshAfterMergeWithIcebergTableCaching()
.containsExactlyInAnyOrder(row(23, "test"), row(24, "test24"));
}

@Test
public void testRenameTableToMissingNamespace()
throws NessieNotFoundException, NessieNamespaceAlreadyExistsException {
createBranchForTest(refName);
api.createNamespace().refName(refName).namespace(Namespace.of("db")).create();
Reference ref = api.getReference().refName(refName).get();

assertThat(sql("USE REFERENCE %s IN nessie", refName))
.hasSize(1)
.containsExactly(row("Branch", refName, ref.getHash()));

sql("CREATE TABLE nessie.db.tbl (id int, name string)");
sql("INSERT INTO nessie.db.tbl select 23, \"test\"");
assertThat(sql("SELECT * FROM nessie.db.tbl")).hasSize(1).containsExactly(row(23, "test"));

// rename to the table identifier with non-existing namespace
assertThatThrownBy(() -> sql("ALTER TABLE nessie.db.tbl RENAME TO nessie.non_existing.table"))
.isInstanceOf(RuntimeException.class)
.hasMessage(
"Cannot rename table 'tbl' to 'table': the current reference is not up to date.");
}

@Test
void testCreateBranchIfNotExists() throws NessieNotFoundException {
createBranchForTest(refName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ private void commitAddPut(
// Check for a Delete-op in the same commit, representing a rename operation.
UUID expectedContentID = UUID.fromString(putValueId);
deletedKey = deleted.remove(expectedContentID);
// consider a content as new content for rename operation to consider for namespace validation
newContent.put(putKey, putValue);
}
if (storeKeyExists && putValueId == null && deleted.containsValue(storeKey)) {
// Check for a Delete-op with same key in the same commit, representing a re-add operation.
Expand Down

0 comments on commit 8001a28

Please sign in to comment.