Uh oh!
There was an error while loading. Please reload this page.
Spark 3.4: Create non-existing Tag/Branch when using CREATE OR REPLACE - #8086
Conversation
| } | ||
| @Test | ||
| public void replaceBranch() throws NoSuchTableException { |
There was a problem hiding this comment.
there was a test gap for branches where a pure replace and a replace on a non-existing branch wasn't exercised, therefore I added replaceBranch() / replaceBranchDoesNotExist() / createOrReplace() (similar tests already exist in TestTagDDL)
Uh oh!
There was an error while loading. Please reload this page.
e9e31d0 to
b501628Compare| val manageSnapshot = iceberg.table.manageSnapshots() | ||
| if (!replace) { | ||
| if (create && replace && null == iceberg.table().refs().get(tag)) { |
There was a problem hiding this comment.
This is a little hard to reason through, what about simplifying to something more like:
valexists=null== iceberg.table().refs().get(tag)
if (create &&!exists) {
if (exists && ifNotExists) {
returnNil
}
manageSnapshot.createTag(tag, snapshotId)
} elseif (replace && exists) {
manageSnapshot.replaceTag(tag, snapshotId)
}There was a problem hiding this comment.
that will change the expected behavior unfortunaly. Tests are expecting ALTER TABLE x REPLACE TAG non-existing to throw an exception, therefore we need to distinguish whether CREATE OR REPLACE is used here vs REPLACE
There was a problem hiding this comment.
Would removing the exists variable from the second if statement achieve that? Then it would always call replaceTag if it's not a create and result in the expected throw?
There was a problem hiding this comment.
yes, this would restore the behavior I mentioned above, but it would change a different behavior where ALTER TABLE x CREATE TAG t is expected to fail when t already exists. The conditions are quite tricky unfortunately and from what I've seen is that we need to explicitly handle create && replace && !refExists
fe5a55f to
763dfcdCompareCurrently, executing `ALTER TABLE x CREATE OR REPLACE TAG xyz` will fail with `Tag does not exist: xyz`. As a user I'd expect this to create the tag due to the `CREATE OR REPLACE` usage. The same issue happens with branches.
763dfcd to
bc2addcCompareThis is based on apache#7097, and back-ports bug fixesapache#7652 and apache#8086
Currently, executing
ALTER TABLE x CREATE OR REPLACE TAG xyzwill fail withTag does not exist: xyz.As a user I'd expect this to create the tag due to the
CREATE OR REPLACEusage. The same issue happens with branches.