Search in sources :

Example 1 with Put

use of org.projectnessie.model.Operation.Put in project nessie by projectnessie.

the class ITUpgradePath method commit.

@Test
@Order(103)
void commit() throws Exception {
    ContentKey key = ContentKey.of("my", "tables", "table_name");
    IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id-" + version);
    String commitMessage = "hello world " + version;
    Put operation = Put.of(key, content);
    Branch branchNew = commitMaybeRetry(api.commitMultipleOperations().commitMeta(CommitMeta.fromMessage(commitMessage)).operation(operation).branch(versionBranch));
    assertThat(branchNew).isNotEqualTo(versionBranch).extracting(Branch::getName).isEqualTo(versionBranch.getName());
    expectedRefLogEntry("COMMIT");
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) Put(org.projectnessie.model.Operation.Put) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 2 with Put

use of org.projectnessie.model.Operation.Put in project nessie by projectnessie.

the class NamespaceApiImpl method createNamespace.

@Override
public Namespace createNamespace(NamespaceParams params) throws NessieNamespaceAlreadyExistsException, NessieReferenceNotFoundException {
    try {
        BranchName branch = branchFromRefName(params.getRefName());
        Callable<Void> validator = () -> {
            if (getExplicitlyCreatedNamespace(params, branch).isPresent()) {
                throw namespaceAlreadyExistsException(params);
            }
            if (getImplicitlyCreatedNamespace(params, branch).isPresent()) {
                throw namespaceAlreadyExistsException(params);
            }
            return null;
        };
        Namespace namespace = params.getNamespace();
        Put put = Put.of(ContentKey.of(namespace.getElements()), namespace);
        commit(branch, "create namespace " + namespace.name(), TreeApiImpl.toOp(put), validator);
        return namespace;
    } catch (ReferenceNotFoundException | ReferenceConflictException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) BranchName(org.projectnessie.versioned.BranchName) Namespace(org.projectnessie.model.Namespace) Put(org.projectnessie.model.Operation.Put)

Example 3 with Put

use of org.projectnessie.model.Operation.Put in project nessie by projectnessie.

the class AbstractCompatibilityTests method commit.

@Test
void commit() throws Exception {
    Branch defaultBranch = api.getDefaultBranch();
    Branch branch = Branch.of("commitToBranch", defaultBranch.getHash());
    Reference created = api.createReference().sourceRefName(defaultBranch.getName()).reference(branch).create();
    assertThat(created).isEqualTo(branch);
    ContentKey key = ContentKey.of("my", "tables", "table_name");
    IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id");
    String commitMessage = "hello world";
    Put operation = Put.of(key, content);
    Branch branchNew = api.commitMultipleOperations().commitMeta(CommitMeta.fromMessage(commitMessage)).operation(operation).branch(branch).commit();
    assertThat(branchNew).isNotEqualTo(branch).extracting(Branch::getName).isEqualTo(branch.getName());
    LogResponse commitLog = api.getCommitLog().refName(branch.getName()).get();
    assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) Put(org.projectnessie.model.Operation.Put) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Test(org.junit.jupiter.api.Test)

Example 4 with Put

use of org.projectnessie.model.Operation.Put in project nessie by projectnessie.

the class AbstractRestGC method fillExpectedContents.

void fillExpectedContents(Branch branch, int numCommits, IdentifiedResult expected) throws NessieNotFoundException {
    fetchLogEntries(branch, numCommits).stream().map(LogEntry::getOperations).filter(Objects::nonNull).flatMap(Collection::stream).filter(op -> op instanceof Put).forEach(op -> {
        Content content = ((Put) op).getContent();
        expected.addContent(branch.getName(), content);
    });
}
Also used : Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Reference(org.projectnessie.model.Reference) NessieConflictException(org.projectnessie.error.NessieConflictException) ArrayList(java.util.ArrayList) Duration(java.time.Duration) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) SparkSession(org.apache.spark.sql.SparkSession) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Objects(java.util.Objects) List(java.util.List) FetchOption(org.projectnessie.api.params.FetchOption) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) CONF_NESSIE_URI(org.projectnessie.client.NessieConfigConstants.CONF_NESSIE_URI) AbstractRest(org.projectnessie.jaxrs.AbstractRest) ContentKey(org.projectnessie.model.ContentKey) Comparator(java.util.Comparator) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Content(org.projectnessie.model.Content) Collection(java.util.Collection) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Put(org.projectnessie.model.Operation.Put)

Example 5 with Put

use of org.projectnessie.model.Operation.Put in project nessie by projectnessie.

the class ITUpgradePath method keysUpgradeAddCommits.

@Test
@Order(203)
void keysUpgradeAddCommits() throws Exception {
    keysUpgradeBranch = (Branch) api.getReference().refName(keysUpgradeBranch.getName()).get();
    Map<ContentKey, IcebergTable> currentKeyValues = keysUpgradeAtHash.getOrDefault(keysUpgradeBranch.getHash(), Collections.emptyMap());
    for (int i = 0; i < keysUpgradeCommitsPerVersion; i++) {
        ContentKey key = ContentKey.of("keys.upgrade.table" + i);
        if ((i % 10) == 9) {
            keysUpgradeBranch = commitMaybeRetry(api.commitMultipleOperations().branch(keysUpgradeBranch).commitMeta(CommitMeta.fromMessage("Commit #" + i + "/delete from Nessie version " + version)).operation(Delete.of(key)));
            Map<ContentKey, IcebergTable> newKeyValues = new HashMap<>(currentKeyValues);
            newKeyValues.remove(key);
            keysUpgradeAtHash.put(keysUpgradeBranch.getHash(), newKeyValues);
        }
        Content currentContent = api.getContent().refName(keysUpgradeBranch.getName()).key(key).get().get(key);
        String cid = currentContent == null ? "table-" + i + "-" + version : currentContent.getId();
        IcebergTable newContent = IcebergTable.of("pointer-" + version + "-commit-" + i, keysUpgradeSequence++, i, i, i, cid);
        Put put = currentContent != null ? Put.of(key, newContent, currentContent) : Put.of(key, newContent);
        keysUpgradeBranch = commitMaybeRetry(api.commitMultipleOperations().branch(keysUpgradeBranch).commitMeta(CommitMeta.fromMessage("Commit #" + i + "/put from Nessie version " + version)).operation(put));
        Map<ContentKey, IcebergTable> newKeyValues = new HashMap<>(currentKeyValues);
        newKeyValues.remove(key);
        keysUpgradeAtHash.put(keysUpgradeBranch.getHash(), newKeyValues);
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Put(org.projectnessie.model.Operation.Put) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Put (org.projectnessie.model.Operation.Put)10 Branch (org.projectnessie.model.Branch)7 ContentKey (org.projectnessie.model.ContentKey)7 IcebergTable (org.projectnessie.model.IcebergTable)7 Test (org.junit.jupiter.api.Test)6 CommitMultipleOperationsBuilder (org.projectnessie.client.api.CommitMultipleOperationsBuilder)4 Content (org.projectnessie.model.Content)4 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 CommitMeta (org.projectnessie.model.CommitMeta)3 Entry (org.projectnessie.model.EntriesResponse.Entry)3 LogResponse (org.projectnessie.model.LogResponse)3 LogEntry (org.projectnessie.model.LogResponse.LogEntry)3 Reference (org.projectnessie.model.Reference)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Order (org.junit.jupiter.api.Order)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2