use of org.projectnessie.model.Branch 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;
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestEntries method filterEntriesByType.
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByType(ReferenceMode refMode) throws BaseNessieClientServerException {
Branch branch = createBranch("filterTypes");
ContentKey a = ContentKey.of("a");
ContentKey b = ContentKey.of("b");
IcebergTable tam = IcebergTable.of("path1", 42, 42, 42, 42);
IcebergView tb = IcebergView.of("pathx", 1, 1, "select * from table", "Dremio");
getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, tam)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
List<Entry> expected = asList(Entry.builder().name(a).type(Type.ICEBERG_TABLE).build(), Entry.builder().name(b).type(Type.ICEBERG_VIEW).build());
assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_TABLE'").get().getEntries();
assertEquals(singletonList(expected.get(0)), entries);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_VIEW'").get().getEntries();
assertEquals(singletonList(expected.get(1)), entries);
entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType in ['ICEBERG_TABLE', 'ICEBERG_VIEW']").get().getEntries();
assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
}
use of org.projectnessie.model.Branch 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.Branch in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testUnknownHashesOnValidNamedRefs.
@Test
public void testUnknownHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testUnknownHashesOnValidNamedRefs");
String invalidHash = "1234567890123456";
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
assertThatThrownBy(() -> getApi().getCommitLog().refName(branch.getName()).hashOnRef(invalidHash).get()).isInstanceOf(NessieNotFoundException.class).hasMessageContaining(String.format("Could not find commit '%s' in reference '%s'.", invalidHash, branch.getName()));
assertThatThrownBy(() -> getApi().getEntries().refName(branch.getName()).hashOnRef(invalidHash).get()).isInstanceOf(NessieNotFoundException.class).hasMessageContaining(String.format("Could not find commit '%s' in reference '%s'.", invalidHash, branch.getName()));
assertThatThrownBy(() -> getApi().getContent().key(ContentKey.of("table0")).refName(branch.getName()).hashOnRef(invalidHash).get()).isInstanceOf(NessieNotFoundException.class).hasMessageContaining(String.format("Could not find commit '%s' in reference '%s'.", invalidHash, branch.getName()));
assertThatThrownBy(() -> getApi().getContent().key(ContentKey.of("table0")).refName(branch.getName()).hashOnRef(invalidHash).get()).isInstanceOf(NessieNotFoundException.class).hasMessageContaining(String.format("Could not find commit '%s' in reference '%s'.", invalidHash, branch.getName()));
}
use of org.projectnessie.model.Branch 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