use of org.projectnessie.model.Reference in project iceberg by apache.
the class NessieCatalog method renameTable.
@Override
public void renameTable(TableIdentifier from, TableIdentifier toOriginal) {
reference.checkMutable();
TableIdentifier to = NessieUtil.removeCatalogName(toOriginal, name());
IcebergTable existingFromTable = table(from);
if (existingFromTable == null) {
throw new NoSuchTableException("table %s doesn't exists", from.name());
}
IcebergTable existingToTable = table(to);
if (existingToTable != null) {
throw new AlreadyExistsException("table %s already exists", to.name());
}
CommitMultipleOperationsBuilder operations = api.commitMultipleOperations().commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg rename table from '%s' to '%s'", from, to), catalogOptions)).operation(Operation.Put.of(NessieUtil.toKey(to), existingFromTable, existingFromTable)).operation(Operation.Delete.of(NessieUtil.toKey(from)));
try {
Tasks.foreach(operations).retry(5).stopRetryOn(NessieNotFoundException.class).throwFailureWhenFinished().onFailure((o, exception) -> refresh()).run(ops -> {
Branch branch = ops.branch(reference.getAsBranch()).commit();
reference.updateReference(branch);
}, BaseNessieClientServerException.class);
} catch (NessieNotFoundException e) {
// and removed by another.
throw new RuntimeException("Failed to drop table as ref is no longer valid.", e);
} catch (BaseNessieClientServerException e) {
throw new CommitFailedException(e, "Failed to rename table: the current reference is not up to date.");
} catch (HttpClientException ex) {
// safe than sorry.
throw new CommitStateUnknownException(ex);
}
// Intentionally just "throw through" Nessie's HttpClientException here and do not "special case"
// just the "timeout" variant to propagate all kinds of network errors (e.g. connection reset).
// Network code implementation details and all kinds of network devices can induce unexpected
// behavior. So better be safe than sorry.
}
use of org.projectnessie.model.Reference in project iceberg by apache.
the class UpdateableReference method refresh.
public boolean refresh(NessieApiV1 api) throws NessieNotFoundException {
if (!mutable) {
return false;
}
Reference oldReference = reference;
reference = api.getReference().refName(reference.getName()).get();
return !oldReference.equals(reference);
}
use of org.projectnessie.model.Reference in project iceberg by apache.
the class TestBranchVisibility method after.
@AfterEach
public void after() throws NessieNotFoundException, NessieConflictException {
catalog.dropTable(tableIdentifier1);
catalog.dropTable(tableIdentifier2);
catalog.refresh();
for (Reference reference : api.getAllReferences().get().getReferences()) {
if (!reference.getName().equals("main")) {
api.deleteBranch().branch((Branch) reference).delete();
}
}
testCatalog = null;
}
use of org.projectnessie.model.Reference in project nessie by projectnessie.
the class AbstractSparkSqlTest method testAssignBranchTo.
@Test
void testAssignBranchTo() throws NessieConflictException, NessieNotFoundException {
String random = "randomBranch";
assertThat(sql("CREATE BRANCH %s IN nessie", random)).containsExactly(row("Branch", random, hash));
commitAndReturnLog(refName);
sql("USE REFERENCE %s IN nessie", refName);
sql("MERGE BRANCH %s INTO main IN nessie", refName);
Reference main = api.getReference().refName("main").get();
assertThat(sql("ASSIGN BRANCH %s TO main IN nessie", random)).containsExactly(row("Branch", random, main.getHash()));
for (Object[] commit : fetchLog("main")) {
String currentHash = (String) commit[2];
assertThat(sql("ASSIGN BRANCH %s TO main AT %s IN nessie", random, currentHash)).containsExactly(row("Branch", random, currentHash));
}
String invalidHash = "abc";
String unknownHash = "dd8d46a3dd5478ce69749a5455dba29d74f6d1171188f4c21d0e15ff4a0a9a9c";
String invalidBranch = "invalidBranch";
assertThatThrownBy(() -> sql("ASSIGN BRANCH %s TO main AT %s IN nessie", random, invalidHash)).isInstanceOf(IllegalArgumentException.class).hasMessage(Validation.HASH_MESSAGE + " - but was: " + invalidHash);
assertThatThrownBy(() -> sql("ASSIGN BRANCH %s TO main AT %s IN nessie", random, unknownHash)).isInstanceOf(NessieNotFoundException.class).hasMessage(String.format("Could not find commit '%s' in reference '%s'.", unknownHash, "main"));
assertThatThrownBy(() -> sql("ASSIGN BRANCH %s TO %s AT %s IN nessie", random, invalidBranch, hash)).isInstanceOf(NessieNotFoundException.class).hasMessage(String.format("Named reference '%s' not found", invalidBranch));
}
use of org.projectnessie.model.Reference in project nessie by projectnessie.
the class AbstractSparkSqlTest method testAssignBranch.
@Test
void testAssignBranch() throws NessieConflictException, NessieNotFoundException {
String random = "randomBranch";
assertThat(sql("CREATE BRANCH %s IN nessie", random)).containsExactly(row("Branch", random, hash));
commitAndReturnLog(refName);
sql("USE REFERENCE %s IN nessie", refName);
sql("MERGE BRANCH %s INTO main IN nessie", refName);
Reference main = api.getReference().refName("main").get();
assertThat(sql("ASSIGN BRANCH %s IN nessie", random)).containsExactly(row("Branch", random, main.getHash()));
}
Aggregations