Search in sources :

Example 1 with Namespace

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();
}
Also used : ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) DeltaLakeTable(org.projectnessie.model.DeltaLakeTable) Content(org.projectnessie.model.Content) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ByteString(com.google.protobuf.ByteString) ImmutableNamespace(org.projectnessie.model.ImmutableNamespace) Namespace(org.projectnessie.model.Namespace)

Example 2 with Namespace

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");
}
Also used : Branch(org.projectnessie.model.Branch) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 3 with Namespace

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();
}
Also used : LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 4 with Namespace

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();
}
Also used : LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 5 with Namespace

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);
}
Also used : Branch(org.projectnessie.model.Branch) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Aggregations

Namespace (org.projectnessie.model.Namespace)12 Test (org.junit.jupiter.api.Test)6 Branch (org.projectnessie.model.Branch)6 CommitMeta (org.projectnessie.model.CommitMeta)5 NessieNamespaceAlreadyExistsException (org.projectnessie.error.NessieNamespaceAlreadyExistsException)4 NessieNamespaceNotFoundException (org.projectnessie.error.NessieNamespaceNotFoundException)4 Entry (org.projectnessie.model.EntriesResponse.Entry)4 IcebergTable (org.projectnessie.model.IcebergTable)4 LogResponse (org.projectnessie.model.LogResponse)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4 NessieNamespaceNotEmptyException (org.projectnessie.error.NessieNamespaceNotEmptyException)3 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)3 ContentKey (org.projectnessie.model.ContentKey)3 Put (org.projectnessie.model.Operation.Put)3 BranchName (org.projectnessie.versioned.BranchName)3 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 NessieReferenceConflictException (org.projectnessie.error.NessieReferenceConflictException)2