Search in sources :

Example 21 with CommitMeta

use of org.projectnessie.model.CommitMeta in project iceberg by apache.

the class TestNessieTable method verifyCommitMetadata.

private void verifyCommitMetadata() throws NessieNotFoundException {
    // check that the author is properly set
    List<LogEntry> log = api.getCommitLog().refName(BRANCH).get().getLogEntries();
    Assertions.assertThat(log).isNotNull().isNotEmpty().allSatisfy(logEntry -> {
        CommitMeta commit = logEntry.getCommitMeta();
        Assertions.assertThat(commit.getAuthor()).isNotNull().isNotEmpty();
        Assertions.assertThat(commit.getAuthor()).isEqualTo(System.getProperty("user.name"));
        Assertions.assertThat(commit.getProperties().get(NessieUtil.APPLICATION_TYPE)).isEqualTo("iceberg");
        Assertions.assertThat(commit.getMessage()).startsWith("Iceberg");
    });
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry)

Example 22 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class IdentifyContentsPerExecutor method computeLiveContents.

private Map<String, ContentBloomFilter> computeLiveContents(Instant cutOffTimestamp, String reference, Instant droppedRefTime, long bloomFilterSize) {
    try (NessieApiV1 api = GCUtil.getApi(gcParams.getNessieClientConfigs())) {
        boolean isRefDroppedAfterCutoffTimeStamp = droppedRefTime == null || droppedRefTime.compareTo(cutOffTimestamp) >= 0;
        if (!isRefDroppedAfterCutoffTimeStamp) {
            // All the contents for all the keys are expired.
            return new HashMap<>();
        }
        Predicate<CommitMeta> liveCommitPredicate = commitMeta -> commitMeta.getCommitTime().compareTo(cutOffTimestamp) >= 0;
        ImmutableGCStateParamsPerTask gcStateParamsPerTask = ImmutableGCStateParamsPerTask.builder().api(api).reference(GCUtil.deserializeReference(reference)).liveCommitPredicate(liveCommitPredicate).bloomFilterSize(bloomFilterSize).build();
        return walkLiveCommitsInReference(gcStateParamsPerTask);
    }
}
Also used : Operation(org.projectnessie.model.Operation) Detached(org.projectnessie.model.Detached) LogResponse(org.projectnessie.model.LogResponse) Predicate(java.util.function.Predicate) Set(java.util.Set) HashMap(java.util.HashMap) Instant(java.time.Instant) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) Serializable(java.io.Serializable) NessieApiV1(org.projectnessie.client.api.NessieApiV1) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) StreamingUtil(org.projectnessie.client.StreamingUtil) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) Function(org.apache.spark.api.java.function.Function) CommitMeta(org.projectnessie.model.CommitMeta) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) SparkSession(org.apache.spark.sql.SparkSession) HashMap(java.util.HashMap) CommitMeta(org.projectnessie.model.CommitMeta) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 23 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class ITUpgradePath method commitLog.

@Test
@Order(104)
void commitLog() {
    assertThat(api.getAllReferences().get().getReferences().stream().filter(r -> r.getName().startsWith(VERSION_BRANCH_PREFIX))).isNotEmpty().allSatisfy(ref -> {
        String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
        LogResponse commitLog = api.getCommitLog().refName(ref.getName()).get();
        String commitMessage = "hello world " + versionFromRef;
        assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
    }).allSatisfy(ref -> {
        String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
        ContentKey key = ContentKey.of("my", "tables", "table_name");
        IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id-" + versionFromRef);
        Map<ContentKey, Content> contents = api.getContent().reference(ref).key(key).get();
        assertThat(contents).containsExactly(entry(key, content));
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NessieVersion(org.projectnessie.tools.compatibility.api.NessieVersion) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Order(org.junit.jupiter.api.Order) NessieConflictException(org.projectnessie.error.NessieConflictException) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Content(org.projectnessie.model.Content) Branch(org.projectnessie.model.Branch) Set(java.util.Set) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Collectors(java.util.stream.Collectors) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test) NessieUpgradesExtension(org.projectnessie.tools.compatibility.internal.NessieUpgradesExtension) List(java.util.List) Delete(org.projectnessie.model.Operation.Delete) StreamingUtil(org.projectnessie.client.StreamingUtil) Entry(java.util.Map.Entry) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig) ContentKey(org.projectnessie.model.ContentKey) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) NonTransactionalDatabaseAdapterConfig(org.projectnessie.versioned.persist.nontx.NonTransactionalDatabaseAdapterConfig) Version(org.projectnessie.tools.compatibility.api.Version) IntStream(java.util.stream.IntStream) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) RefLogResponseEntry(org.projectnessie.model.RefLogResponse.RefLogResponseEntry) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) ArrayList(java.util.ArrayList) VersionCondition(org.projectnessie.tools.compatibility.api.VersionCondition) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta) NessieAPI(org.projectnessie.tools.compatibility.api.NessieAPI) Tuple(org.assertj.core.groups.Tuple) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.entry(org.assertj.core.api.Assertions.entry) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterEach(org.junit.jupiter.api.AfterEach) IcebergTable(org.projectnessie.model.IcebergTable) Collections(java.util.Collections) ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 24 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class AbstractRestEntries method filterEntriesByNamespaceAndPrefixDepth.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespaceAndPrefixDepth(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch branch = createBranch("filterEntriesByNamespaceAndPrefixDepth");
    ContentKey first = ContentKey.of("a", "b", "c", "firstTable");
    ContentKey second = ContentKey.of("a", "b", "c", "secondTable");
    ContentKey third = ContentKey.of("a", "thirdTable");
    ContentKey fourth = ContentKey.of("a", "b", "fourthTable");
    ContentKey fifth = ContentKey.of("a", "boo", "fifthTable");
    ContentKey withoutNamespace = ContentKey.of("withoutNamespace");
    List<ContentKey> keys = ImmutableList.of(first, second, third, fourth, fifth, withoutNamespace);
    for (int i = 0; i < keys.size(); i++) {
        getApi().commitMultipleOperations().branch(branch).operation(Put.of(keys.get(i), IcebergTable.of("path" + i, 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit " + i)).commit();
    }
    branch = (Branch) getApi().getReference().refName(branch.getName()).get();
    Reference reference = refMode.transform(branch);
    List<Entry> entries = getApi().getEntries().reference(reference).namespaceDepth(0).get().getEntries();
    assertThat(entries).isNotNull().hasSize(6);
    entries = getApi().getEntries().reference(reference).namespaceDepth(0).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).isNotNull().hasSize(5);
    entries = getApi().getEntries().reference(reference).namespaceDepth(1).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(1);
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(2).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(3);
    assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "thirdTable")));
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('a\\\\.b(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(2);
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(4).filter("entry.namespace.matches('a\\\\.b\\\\.c(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(2);
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "firstTable")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "secondTable")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(5).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
    assertThat(entries).isEmpty();
    entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(3);
    assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo", "fifthTable")));
    assumeTrue(ReferenceMode.DETACHED != refMode);
    // check that implicit namespaces are properly detected
    checkNamespaces(reference, Arrays.asList("a", "a.b", "a.boo", "a.b.c"), Arrays.asList(first, second, third, fourth, fifth));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Arrays(java.util.Arrays) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) Put(org.projectnessie.model.Operation.Put) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) Entry(org.projectnessie.model.EntriesResponse.Entry) Reference(org.projectnessie.model.Reference) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Type(org.projectnessie.model.Content.Type) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Branch(org.projectnessie.model.Branch) Collectors(java.util.stream.Collectors) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Namespace(org.projectnessie.model.Namespace) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class AbstractRestMergeTransplant method merge.

@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void merge(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
    Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(ContentKey.of("key1"), table1)).commit();
    assertThat(committed1.getHash()).isNotNull();
    Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(ContentKey.of("key1"), table1, table1)).commit();
    assertThat(committed2.getHash()).isNotNull();
    int commitsToMerge = 2;
    LogResponse logBranch = getApi().getCommitLog().refName(branch.getName()).untilHash(branch.getHash()).maxRecords(commitsToMerge).get();
    getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(ContentKey.of("key2"), table2)).commit();
    getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "test-merge-main");
    // Verify that the commit-timestamp was updated
    LogResponse logOfMerged = getApi().getCommitLog().refName(base.getName()).maxRecords(commitsToMerge).get();
    assertThat(logOfMerged.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime)).isNotEqualTo(logBranch.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime));
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(e -> e.getName().getName())).containsExactlyInAnyOrder("key1", "key2");
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5