use of org.projectnessie.model.Namespace in project nessie by projectnessie.
the class TableCommitMetaStoreWorker method toStoreOnReferenceState.
@Override
public ByteString toStoreOnReferenceState(Content content) {
ObjectTypes.Content.Builder builder = ObjectTypes.Content.newBuilder().setId(content.getId());
if (content instanceof IcebergTable) {
IcebergTable state = (IcebergTable) content;
ObjectTypes.IcebergRefState.Builder stateBuilder = ObjectTypes.IcebergRefState.newBuilder().setSnapshotId(state.getSnapshotId()).setSchemaId(state.getSchemaId()).setSpecId(state.getSpecId()).setSortOrderId(state.getSortOrderId());
builder.setIcebergRefState(stateBuilder);
} else if (content instanceof IcebergView) {
IcebergView view = (IcebergView) content;
builder.setIcebergViewState(ObjectTypes.IcebergViewState.newBuilder().setVersionId(view.getVersionId()).setSchemaId(view.getSchemaId()).setDialect(view.getDialect()).setSqlText(view.getSqlText()));
} else if (content instanceof DeltaLakeTable) {
ObjectTypes.DeltaLakeTable.Builder table = ObjectTypes.DeltaLakeTable.newBuilder().addAllMetadataLocationHistory(((DeltaLakeTable) content).getMetadataLocationHistory()).addAllCheckpointLocationHistory(((DeltaLakeTable) content).getCheckpointLocationHistory());
String lastCheckpoint = ((DeltaLakeTable) content).getLastCheckpoint();
if (lastCheckpoint != null) {
table.setLastCheckpoint(lastCheckpoint);
}
builder.setDeltaLakeTable(table);
} else if (content instanceof Namespace) {
builder.setNamespace(ObjectTypes.Namespace.newBuilder().setName(((Namespace) content).name()));
} else {
throw new IllegalArgumentException("Unknown type " + content);
}
return builder.build().toByteString();
}
use of org.projectnessie.model.Namespace in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaces.
@Test
public void testNamespaces() throws BaseNessieClientServerException {
Branch branch = createBranch("testNamespaces");
Namespace ns = Namespace.parse("a.b.c");
Namespace namespace = getApi().createNamespace().refName(branch.getName()).namespace(ns).create();
assertThat(namespace).isNotNull().isEqualTo(ns);
assertThat(getApi().getNamespace().refName(branch.getName()).namespace(ns).get()).isEqualTo(namespace);
assertThatThrownBy(() -> getApi().createNamespace().refName(branch.getName()).namespace(ns).create()).isInstanceOf(NessieNamespaceAlreadyExistsException.class).hasMessage("Namespace 'a.b.c' already exists");
getApi().deleteNamespace().refName(branch.getName()).namespace(ns).delete();
assertThatThrownBy(() -> getApi().deleteNamespace().refName(branch.getName()).namespace(ns).delete()).isInstanceOf(NessieNamespaceNotFoundException.class).hasMessage("Namespace 'a.b.c' does not exist");
assertThatThrownBy(() -> getApi().getNamespace().refName(branch.getName()).namespace(ns).get()).isInstanceOf(NessieNamespaceNotFoundException.class).hasMessage("Namespace 'a.b.c' does not exist");
assertThatThrownBy(() -> getApi().deleteNamespace().refName(branch.getName()).namespace(Namespace.parse("nonexisting")).delete()).isInstanceOf(NessieNamespaceNotFoundException.class).hasMessage("Namespace 'nonexisting' does not exist");
}
use of org.projectnessie.model.Namespace in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceMerge.
@Test
public void testNamespaceMerge() throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
Namespace ns = Namespace.parse("a.b.c");
// create the same namespace on both branches
getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
getApi().createNamespace().namespace(ns).refName(base.getName()).create();
base = (Branch) getApi().getReference().refName(base.getName()).get();
branch = (Branch) getApi().getReference().refName(branch.getName()).get();
getApi().mergeRefIntoBranch().branch(base).fromRef(branch).merge();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
String expectedCommitMsg = "create namespace a.b.c";
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly(expectedCommitMsg, expectedCommitMsg);
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
use of org.projectnessie.model.Namespace in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceMergeWithConflict.
@Test
public void testNamespaceMergeWithConflict() throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
Namespace ns = Namespace.parse("a.b.c");
// create a namespace on the base branch
getApi().createNamespace().namespace(ns).refName(base.getName()).create();
base = (Branch) getApi().getReference().refName(base.getName()).get();
// create a table with the same name on the other branch
IcebergTable table = IcebergTable.of("merge-table1", 42, 42, 42, 42);
branch = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(ContentKey.of("a", "b", "c"), table)).commit();
Branch finalBase = base;
Branch finalBranch = branch;
assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branch(finalBase).fromRef(finalBranch).merge()).isInstanceOf(NessieReferenceConflictException.class).hasMessage("The following keys have been changed in conflict: 'a.b.c'");
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
// merging should not have been possible ("test-merge-branch1" shouldn't be in the commits)
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("create namespace a.b.c");
List<Entry> entries = getApi().getEntries().refName(base.getName()).get().getEntries();
assertThat(entries.stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
use of org.projectnessie.model.Namespace in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespacesRetrieval.
@Test
public void testNamespacesRetrieval() throws BaseNessieClientServerException {
Branch branch = createBranch("namespace");
Namespace one = Namespace.parse("a.b.c");
Namespace two = Namespace.parse("a.b.d");
Namespace three = Namespace.parse("x.y.z");
Namespace four = Namespace.parse("one.two");
for (Namespace namespace : Arrays.asList(one, two, three, four)) {
assertThat(getApi().createNamespace().refName(branch.getName()).namespace(namespace).create()).isNotNull();
}
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).get().getNamespaces()).containsExactlyInAnyOrder(one, two, three, four);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace(Namespace.EMPTY).get().getNamespaces()).containsExactlyInAnyOrder(one, two, three, four);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("a").get().getNamespaces()).containsExactlyInAnyOrder(one, two);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("a.b").get().getNamespaces()).containsExactlyInAnyOrder(one, two);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("a.b.c").get().getNamespaces()).containsExactlyInAnyOrder(one);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("a.b.d").get().getNamespaces()).containsExactlyInAnyOrder(two);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("x").get().getNamespaces()).containsExactly(three);
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("z").get().getNamespaces()).isEmpty();
assertThat(getApi().getMultipleNamespaces().refName(branch.getName()).namespace("on").get().getNamespaces()).containsExactly(four);
}
Aggregations