use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class TestNessieIcebergViews method verifyViewInNessie.
private void verifyViewInNessie(TableIdentifier viewIdentifier, View icebergView) throws NessieNotFoundException {
ContentKey contentKey = ContentKey.of(viewIdentifier.toString().split("\\."));
Map<ContentKey, Content> contentMap = api.getContent().key(contentKey).refName(BRANCH).get();
assertThat(contentMap).hasSize(1).containsKey(contentKey);
Content content = contentMap.get(contentKey);
assertThat(content.unwrap(IcebergView.class)).isPresent();
IcebergView view = content.unwrap(IcebergView.class).get();
assertThat(metadataFilesForViewsPath(viewIdentifier.name())).contains(view.getMetadataLocation());
// TODO: currently the schema id is always 0
assertThat(view.getSchemaId()).isEqualTo(icebergView.currentVersion().viewDefinition().schema().schemaId());
assertThat(view.getVersionId()).isEqualTo(view.getVersionId());
assertThat(view.getSqlText()).isEqualTo(icebergView.currentVersion().viewDefinition().sql());
// TODO: currently not implemented in the view definition
// assertThat(view.getDialect()).isEqualTo(viewDefinition.dialect());
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractSparkSqlTest method commitAndReturnLog.
private List<Object[]> commitAndReturnLog(String branch) throws NessieConflictException, NessieNotFoundException {
assertThat(sql("CREATE BRANCH %s IN nessie", branch)).containsExactly(row("Branch", branch, hash));
ContentKey key = ContentKey.of("table", "name");
CommitMeta cm1 = ImmutableCommitMeta.builder().author("sue").authorTime(Instant.ofEpochMilli(1)).message("1").putProperties("test", "123").build();
CommitMeta cm2 = ImmutableCommitMeta.builder().author("janet").authorTime(Instant.ofEpochMilli(10)).message("2").putProperties("test", "123").build();
CommitMeta cm3 = ImmutableCommitMeta.builder().author("alice").authorTime(Instant.ofEpochMilli(100)).message("3").putProperties("test", "123").build();
Operations ops = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42))).commitMeta(cm1).build();
Operations ops2 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42))).commitMeta(cm2).build();
Operations ops3 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("baz", 42, 42, 42, 42))).commitMeta(cm3).build();
Branch ref1 = api.commitMultipleOperations().branchName(branch).hash(hash).operations(ops.getOperations()).commitMeta(ops.getCommitMeta()).commit();
Branch ref2 = api.commitMultipleOperations().branchName(branch).hash(ref1.getHash()).operations(ops2.getOperations()).commitMeta(ops2.getCommitMeta()).commit();
Branch ref3 = api.commitMultipleOperations().branchName(branch).hash(ref2.getHash()).operations(ops3.getOperations()).commitMeta(ops3.getCommitMeta()).commit();
List<Object[]> resultList = new ArrayList<>();
resultList.add(cmToRow(cm3, ref3.getHash()));
resultList.add(cmToRow(cm2, ref2.getHash()));
resultList.add(cmToRow(cm1, ref1.getHash()));
return resultList;
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class ITUpgradePath method commit.
@Test
@Order(103)
void commit() throws Exception {
ContentKey key = ContentKey.of("my", "tables", "table_name");
IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id-" + version);
String commitMessage = "hello world " + version;
Put operation = Put.of(key, content);
Branch branchNew = commitMaybeRetry(api.commitMultipleOperations().commitMeta(CommitMeta.fromMessage(commitMessage)).operation(operation).branch(versionBranch));
assertThat(branchNew).isNotEqualTo(versionBranch).extracting(Branch::getName).isEqualTo(versionBranch.getName());
expectedRefLogEntry("COMMIT");
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class GenerateContent method execute.
@Override
public void execute() throws BaseNessieClientServerException {
if (runtimeDuration != null) {
if (runtimeDuration.isZero() || runtimeDuration.isNegative()) {
throw new ParameterException(spec.commandLine(), "Duration must be absent to greater than zero.");
}
}
Duration perCommitDuration = Optional.ofNullable(runtimeDuration).orElse(Duration.ZERO).dividedBy(numCommits);
ThreadLocalRandom random = ThreadLocalRandom.current();
String runStartTime = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(LocalDateTime.now());
List<ContentKey> tableNames = IntStream.range(0, numTables).mapToObj(i -> ContentKey.of(String.format("create-contents-%s", runStartTime), "contents", Integer.toString(i))).collect(Collectors.toList());
try (NessieApiV1 api = createNessieApiInstance()) {
Branch defaultBranch;
if (defaultBranchName == null) {
// Use the server's default branch.
defaultBranch = api.getDefaultBranch();
} else {
// Use the specified default branch.
try {
defaultBranch = (Branch) api.getReference().refName(defaultBranchName).get();
} catch (NessieReferenceNotFoundException e) {
// Create branch if it does not exist.
defaultBranch = api.getDefaultBranch();
defaultBranch = (Branch) api.createReference().reference(Branch.of(defaultBranchName, defaultBranch.getHash())).sourceRefName(defaultBranch.getName()).create();
}
}
List<String> branches = new ArrayList<>();
branches.add(defaultBranch.getName());
while (branches.size() < branchCount) {
// Create a new branch
String newBranchName = "branch-" + runStartTime + "_" + (branches.size() - 1);
Branch branch = Branch.of(newBranchName, defaultBranch.getHash());
spec.commandLine().getOut().printf("Creating branch '%s' from '%s' at %s%n", branch.getName(), defaultBranch.getName(), branch.getHash());
api.createReference().reference(branch).sourceRefName(defaultBranch.getName()).create();
branches.add(newBranchName);
}
spec.commandLine().getOut().printf("Starting contents generation, %d commits...%n", numCommits);
for (int i = 0; i < numCommits; i++) {
// Choose a random branch to commit to
String branchName = branches.get(random.nextInt(branches.size()));
Branch commitToBranch = (Branch) api.getReference().refName(branchName).get();
ContentKey tableName = tableNames.get(random.nextInt(tableNames.size()));
Content tableContents = api.getContent().refName(branchName).key(tableName).get().get(tableName);
Content newContents = createContents(tableContents, random);
spec.commandLine().getOut().printf("Committing content-key '%s' to branch '%s' at %s%n", tableName, commitToBranch.getName(), commitToBranch.getHash());
CommitMultipleOperationsBuilder commit = api.commitMultipleOperations().branch(commitToBranch).commitMeta(CommitMeta.builder().message(String.format("%s table %s on %s, commit #%d of %d", tableContents != null ? "Update" : "Create", tableName, branchName, i, numCommits)).author(System.getProperty("user.name")).authorTime(Instant.now()).build());
if (newContents instanceof IcebergTable || newContents instanceof IcebergView) {
commit.operation(Put.of(tableName, newContents, tableContents));
} else {
commit.operation(Put.of(tableName, newContents));
}
Branch newHead = commit.commit();
if (random.nextDouble() < newTagProbability) {
Tag tag = Tag.of("new-tag-" + random.nextLong(), newHead.getHash());
spec.commandLine().getOut().printf("Creating tag '%s' from '%s' at %s%n", tag.getName(), branchName, tag.getHash());
api.createReference().reference(tag).sourceRefName(branchName).create();
}
try {
TimeUnit.NANOSECONDS.sleep(perCommitDuration.toNanos());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
spec.commandLine().getOut().printf("Done creating contents.%n");
}
use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class ReadContent method execute.
@Override
public void execute() throws NessieNotFoundException {
try (NessieApiV1 api = createNessieApiInstance()) {
ContentKey contentKey = ContentKey.of(key);
spec.commandLine().getOut().printf("Reading content for key '%s'\n\n", contentKey);
Map<ContentKey, Content> contentMap = api.getContent().refName(ref).key(contentKey).get();
for (Map.Entry<ContentKey, Content> entry : contentMap.entrySet()) {
spec.commandLine().getOut().printf("Key: %s\n", entry.getKey());
if (isVerbose()) {
List<String> key = entry.getKey().getElements();
for (int i = 0; i < key.size(); i++) {
spec.commandLine().getOut().printf(" key[%d]: %s\n", i, key.get(i));
}
}
spec.commandLine().getOut().printf("Value: %s\n", entry.getValue());
}
spec.commandLine().getOut().printf("\nDone reading content for key '%s'\n\n", contentKey);
}
}
Aggregations