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