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));
}
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);
}
}
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);
}
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);
}
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());
}
Aggregations