Search in sources :

Example 26 with Content

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

the class TestStoreWorker method testSerde.

@ParameterizedTest
@MethodSource("provideDeserialization")
void testSerde(Map.Entry<ByteString, Content> entry) {
    ByteString actualBytes = worker.toStoreOnReferenceState(entry.getValue());
    Assertions.assertEquals(entry.getValue(), worker.valueFromStore(actualBytes, Optional.empty()));
    Content actualContent = worker.valueFromStore(entry.getKey(), Optional.empty());
    Assertions.assertEquals(entry.getKey(), worker.toStoreOnReferenceState(actualContent));
}
Also used : ByteString(com.google.protobuf.ByteString) Content(org.projectnessie.model.Content) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with Content

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

the class TreeApiImpl method getCommitLog.

@Override
public LogResponse getCommitLog(String namedRef, CommitLogParams params) throws NessieNotFoundException {
    int max = Math.min(params.maxRecords() != null ? params.maxRecords() : MAX_COMMIT_LOG_ENTRIES, MAX_COMMIT_LOG_ENTRIES);
    // we should only allow named references when no paging is defined
    Ref endRef = namedRefWithHashOrThrow(namedRef, null == params.pageToken() ? params.endHash() : params.pageToken()).getHash();
    boolean fetchAll = FetchOption.isFetchAll(params.fetchOption());
    try (Stream<Commit<CommitMeta, Content>> commits = getStore().getCommits(endRef, fetchAll)) {
        Stream<LogEntry> logEntries = commits.map(commit -> {
            CommitMeta commitMetaWithHash = addHashToCommitMeta(commit.getHash(), commit.getCommitMeta());
            ImmutableLogEntry.Builder logEntry = LogEntry.builder();
            logEntry.commitMeta(commitMetaWithHash);
            if (fetchAll) {
                if (commit.getParentHash() != null) {
                    logEntry.parentCommitHash(commit.getParentHash().asString());
                }
                if (commit.getOperations() != null) {
                    commit.getOperations().forEach(op -> {
                        ContentKey key = ContentKey.of(op.getKey().getElements());
                        if (op instanceof Put) {
                            Content content = ((Put<Content>) op).getValue();
                            logEntry.addOperations(Operation.Put.of(key, content));
                        }
                        if (op instanceof Delete) {
                            logEntry.addOperations(Operation.Delete.of(key));
                        }
                    });
                }
            }
            return logEntry.build();
        });
        logEntries = StreamSupport.stream(StreamUtil.takeUntilIncl(logEntries.spliterator(), x -> Objects.equals(x.getCommitMeta().getHash(), params.startHash())), false);
        List<LogEntry> items = filterCommitLog(logEntries, params.filter()).limit(max + 1).collect(Collectors.toList());
        if (items.size() == max + 1) {
            return ImmutableLogResponse.builder().addAllLogEntries(items.subList(0, max)).isHasMore(true).token(items.get(max).getCommitMeta().getHash()).build();
        }
        return ImmutableLogResponse.builder().addAllLogEntries(items).build();
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Delete(org.projectnessie.versioned.Delete) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Put(org.projectnessie.versioned.Put) ContentKey(org.projectnessie.model.ContentKey) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Commit(org.projectnessie.versioned.Commit) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry)

Example 28 with Content

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

the class TestStoreWorker method getDelta.

private static Map.Entry<ByteString, Content> getDelta() {
    String path = "foo/bar";
    String cl1 = "xyz";
    String cl2 = "abc";
    String ml1 = "efg";
    String ml2 = "hij";
    Content content = ImmutableDeltaLakeTable.builder().lastCheckpoint(path).addCheckpointLocationHistory(cl1).addCheckpointLocationHistory(cl2).addMetadataLocationHistory(ml1).addMetadataLocationHistory(ml2).id(ID).build();
    ByteString bytes = ObjectTypes.Content.newBuilder().setId(ID).setDeltaLakeTable(ObjectTypes.DeltaLakeTable.newBuilder().setLastCheckpoint(path).addCheckpointLocationHistory(cl1).addCheckpointLocationHistory(cl2).addMetadataLocationHistory(ml1).addMetadataLocationHistory(ml2)).build().toByteString();
    return new AbstractMap.SimpleImmutableEntry<>(bytes, content);
}
Also used : Content(org.projectnessie.model.Content) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString)

Example 29 with Content

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

the class TestStoreWorker method getNamespace.

private static Map.Entry<ByteString, Content> getNamespace() {
    String name = "a.b.c";
    Content content = ImmutableNamespace.builder().id(name).name(name).build();
    ByteString bytes = ObjectTypes.Content.newBuilder().setId(name).setNamespace(ObjectTypes.Namespace.newBuilder().setName(name).build()).build().toByteString();
    return new AbstractMap.SimpleImmutableEntry<>(bytes, content);
}
Also used : Content(org.projectnessie.model.Content) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString)

Example 30 with Content

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

the class ITDeltaLogBranches method testCheckpoint.

@Test
void testCheckpoint() throws NessieNotFoundException {
    Dataset<Row> targetTable = createKVDataSet(Arrays.asList(tuple2(1, 10), tuple2(2, 20), tuple2(3, 30), tuple2(4, 40)), "key", "value");
    // write some data to table
    targetTable.write().format("delta").save(tempPath.getAbsolutePath());
    // write enough to trigger a checkpoint generation
    for (int i = 0; i < 15; i++) {
        targetTable.write().format("delta").mode("append").save(tempPath.getAbsolutePath());
    }
    DeltaTable target = DeltaTable.forPath(spark, tempPath.getAbsolutePath());
    int expectedSize = target.toDF().collectAsList().size();
    Assertions.assertEquals(64, expectedSize);
    String tableName = tempPath.getAbsolutePath() + "/_delta_log";
    ContentKey key = ContentKey.of(tableName.split("/"));
    Content content = api.getContent().key(key).refName("main").get().get(key);
    Optional<DeltaLakeTable> table = content.unwrap(DeltaLakeTable.class);
    Assertions.assertTrue(table.isPresent());
    Assertions.assertEquals(1, table.get().getCheckpointLocationHistory().size());
    Assertions.assertEquals(5, table.get().getMetadataLocationHistory().size());
    Assertions.assertNotNull(table.get().getLastCheckpoint());
}
Also used : DeltaTable(io.delta.tables.DeltaTable) ContentKey(org.projectnessie.model.ContentKey) DeltaLakeTable(org.projectnessie.model.DeltaLakeTable) Content(org.projectnessie.model.Content) Row(org.apache.spark.sql.Row) Test(org.junit.jupiter.api.Test)

Aggregations

Content (org.projectnessie.model.Content)32 ContentKey (org.projectnessie.model.ContentKey)16 CommitMeta (org.projectnessie.model.CommitMeta)11 IcebergTable (org.projectnessie.model.IcebergTable)11 Test (org.junit.jupiter.api.Test)9 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)9 Branch (org.projectnessie.model.Branch)8 Map (java.util.Map)7 ByteString (com.google.protobuf.ByteString)6 IcebergView (org.projectnessie.model.IcebergView)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 Reference (org.projectnessie.model.Reference)5 Instant (java.time.Instant)4 ArrayList (java.util.ArrayList)4 LogResponse (org.projectnessie.model.LogResponse)4 Put (org.projectnessie.model.Operation.Put)4 HashSet (java.util.HashSet)3