Search in sources :

Example 21 with Reference

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

the class IdentifyContentsPerExecutor method handleCommitForExpiredContents.

private static void handleCommitForExpiredContents(Reference reference, LogResponse.LogEntry logEntry, Map<String, ContentBloomFilter> liveContentsBloomFilterMap, IdentifiedResult result) {
    if (logEntry.getOperations() != null) {
        logEntry.getOperations().stream().filter(operation -> operation instanceof Operation.Put).forEach(operation -> {
            Content content = ((Operation.Put) operation).getContent();
            ContentBloomFilter bloomFilter = liveContentsBloomFilterMap.get(content.getId());
            // But live contents never be considered as expired.
            if (bloomFilter == null || !bloomFilter.mightContain(content)) {
                result.addContent(reference.getName(), content);
            }
        });
    }
}
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) Content(org.projectnessie.model.Content)

Example 22 with Reference

use of org.projectnessie.model.Reference 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 Reference

use of org.projectnessie.model.Reference 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 Reference

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

the class AbstractSparkSqlTest method removeBranches.

@AfterEach
void removeBranches() throws NessieConflictException, NessieNotFoundException {
    for (Reference ref : api.getAllReferences().get().getReferences()) {
        if (ref instanceof Branch) {
            api.deleteBranch().branchName(ref.getName()).hash(ref.getHash()).delete();
        }
        if (ref instanceof Tag) {
            api.deleteTag().tagName(ref.getName()).hash(ref.getHash()).delete();
        }
    }
    api.createReference().reference(Branch.of("main", null)).create();
    api.close();
    api = null;
}
Also used : Reference(org.projectnessie.model.Reference) Branch(org.projectnessie.model.Branch) Tag(org.projectnessie.model.Tag) AfterEach(org.junit.jupiter.api.AfterEach)

Example 25 with Reference

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

the class AbstractSparkSqlTest method testAssignTag.

@Test
void testAssignTag() throws NessieConflictException, NessieNotFoundException {
    String random = "randomTag";
    assertThat(sql("CREATE TAG %s IN nessie", random)).containsExactly(row("Tag", 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 TAG %s IN nessie", random)).containsExactly(row("Tag", random, main.getHash()));
}
Also used : Reference(org.projectnessie.model.Reference) Test(org.junit.jupiter.api.Test)

Aggregations

Reference (org.projectnessie.model.Reference)38 Branch (org.projectnessie.model.Branch)19 Test (org.junit.jupiter.api.Test)17 ContentKey (org.projectnessie.model.ContentKey)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)10 CommitMeta (org.projectnessie.model.CommitMeta)10 IcebergTable (org.projectnessie.model.IcebergTable)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 LogResponse (org.projectnessie.model.LogResponse)9 Tag (org.projectnessie.model.Tag)9 Put (org.projectnessie.model.Operation.Put)8 Map (java.util.Map)7 Stream (java.util.stream.Stream)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)7 Content (org.projectnessie.model.Content)7 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)6 Operation (org.projectnessie.model.Operation)6