use of org.projectnessie.model.IcebergView in project nessie by projectnessie.
the class TestNessieIcebergViews method testViewColumnComments.
@Test
public void testViewColumnComments() throws NessieNotFoundException {
// update comment
CommentUpdate commentUpdate = new CommentUpdate(catalog.getViewCatalog().newViewOps(VIEW_IDENTIFIER));
String comment = "The column name is id";
commentUpdate.updateColumnDoc("id", comment);
Schema schema = commentUpdate.apply();
assertThat(schema.findField("id").doc()).isEqualTo(comment);
comment = comment + " and type is integer";
commentUpdate.updateColumnDoc("id", comment);
schema = commentUpdate.apply();
assertThat(schema.findField("id").doc()).isEqualTo(comment);
commentUpdate.commit();
View icebergView = catalog.load(VIEW_IDENTIFIER.toString());
assertThat(icebergView).isNotNull();
assertThat(icebergView.currentVersion().versionId()).isEqualTo(2);
assertThat(icebergView.currentVersion().parentId()).isEqualTo(1);
assertThat(icebergView.properties()).isEmpty();
assertThat(Paths.get(metadataLocationViews(VIEW_IDENTIFIER.name()))).exists();
assertThat(metadataFilesForViews(VIEW_IDENTIFIER.name())).isNotNull().hasSize(2);
verifyCommitMetadata();
assertThat(api.getCommitLog().refName(BRANCH).get().getLogEntries()).hasSize(3);
verifyViewInNessie(VIEW_IDENTIFIER, icebergView);
}
use of org.projectnessie.model.IcebergView 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.IcebergView in project nessie by projectnessie.
the class TestNessieIcebergViews method testReplaceView.
@Test
public void testReplaceView() throws NessieNotFoundException {
// add a column
catalog.loadTable(TABLE_IDENTIFIER).updateSchema().addColumn("mother", Types.LongType.get()).commit();
// update schema
Schema schema = catalog.loadTable(TABLE_IDENTIFIER).schema();
ViewDefinition updatedView = ViewDefinition.of(SQL, schema, CATALOG_NAME, new ArrayList<>());
catalog.replace(VIEW_IDENTIFIER.toString(), updatedView, Collections.emptyMap());
View icebergView = catalog.load(VIEW_IDENTIFIER.toString());
assertThat(icebergView).isNotNull();
assertThat(icebergView.currentVersion().versionId()).isEqualTo(2);
assertThat(icebergView.currentVersion().parentId()).isEqualTo(1);
assertThat(icebergView.currentVersion().viewDefinition()).isEqualTo(updatedView);
assertThat(icebergView.properties()).isEmpty();
assertThat(Paths.get(metadataLocationViews(VIEW_IDENTIFIER.name()))).exists();
assertThat(metadataFilesForViews(VIEW_IDENTIFIER.name())).isNotNull().hasSize(2);
verifyViewInNessie(VIEW_IDENTIFIER, icebergView);
// update sql
ViewDefinition updatedSql = ViewDefinition.of(SQL_ALTERED, schema, CATALOG_NAME, new ArrayList<>());
catalog.replace(VIEW_IDENTIFIER.toString(), updatedSql, Collections.emptyMap());
icebergView = catalog.load(VIEW_IDENTIFIER.toString());
assertThat(icebergView).isNotNull();
assertThat(icebergView.currentVersion().versionId()).isEqualTo(3);
assertThat(icebergView.currentVersion().parentId()).isEqualTo(2);
assertThat(icebergView.currentVersion().viewDefinition()).isEqualTo(updatedSql);
assertThat(icebergView.properties()).isEmpty();
assertThat(Paths.get(metadataLocationViews(VIEW_IDENTIFIER.name()))).exists();
assertThat(metadataFilesForViews(VIEW_IDENTIFIER.name())).isNotNull().hasSize(3);
verifyViewInNessie(VIEW_IDENTIFIER, icebergView);
// update properties
Map<String, String> properties = new HashMap<>();
properties.put("prop1", "val1");
properties.put("prop2", "val2");
catalog.replace(VIEW_IDENTIFIER.toString(), ViewDefinition.of(SQL_ALTERED, schema, CATALOG_NAME, new ArrayList<>()), properties);
icebergView = catalog.load(VIEW_IDENTIFIER.toString());
assertThat(icebergView).isNotNull();
assertThat(icebergView.currentVersion().versionId()).isEqualTo(4);
assertThat(icebergView.currentVersion().parentId()).isEqualTo(3);
assertThat(icebergView.currentVersion().viewDefinition()).isEqualTo(updatedSql);
assertThat(icebergView.properties()).isEqualTo(properties);
assertThat(Paths.get(metadataLocationViews(VIEW_IDENTIFIER.name()))).exists();
assertThat(metadataFilesForViews(VIEW_IDENTIFIER.name())).isNotNull().hasSize(4);
verifyCommitMetadata();
assertThat(api.getCommitLog().refName(BRANCH).get().getLogEntries()).hasSize(6);
verifyViewInNessie(VIEW_IDENTIFIER, icebergView);
}
use of org.projectnessie.model.IcebergView in project nessie by projectnessie.
the class TableCommitMetaStoreWorker method toStoreOnReferenceState.
@Override
public ByteString toStoreOnReferenceState(Content content) {
ObjectTypes.Content.Builder builder = ObjectTypes.Content.newBuilder().setId(content.getId());
if (content instanceof IcebergTable) {
IcebergTable state = (IcebergTable) content;
ObjectTypes.IcebergRefState.Builder stateBuilder = ObjectTypes.IcebergRefState.newBuilder().setSnapshotId(state.getSnapshotId()).setSchemaId(state.getSchemaId()).setSpecId(state.getSpecId()).setSortOrderId(state.getSortOrderId());
builder.setIcebergRefState(stateBuilder);
} else if (content instanceof IcebergView) {
IcebergView view = (IcebergView) content;
builder.setIcebergViewState(ObjectTypes.IcebergViewState.newBuilder().setVersionId(view.getVersionId()).setSchemaId(view.getSchemaId()).setDialect(view.getDialect()).setSqlText(view.getSqlText()));
} else if (content instanceof DeltaLakeTable) {
ObjectTypes.DeltaLakeTable.Builder table = ObjectTypes.DeltaLakeTable.newBuilder().addAllMetadataLocationHistory(((DeltaLakeTable) content).getMetadataLocationHistory()).addAllCheckpointLocationHistory(((DeltaLakeTable) content).getCheckpointLocationHistory());
String lastCheckpoint = ((DeltaLakeTable) content).getLastCheckpoint();
if (lastCheckpoint != null) {
table.setLastCheckpoint(lastCheckpoint);
}
builder.setDeltaLakeTable(table);
} else if (content instanceof Namespace) {
builder.setNamespace(ObjectTypes.Namespace.newBuilder().setName(((Namespace) content).name()));
} else {
throw new IllegalArgumentException("Unknown type " + content);
}
return builder.build().toByteString();
}
use of org.projectnessie.model.IcebergView in project nessie by projectnessie.
the class TestStoreWorker method testSerdeIcebergView.
@Test
void testSerdeIcebergView() {
String path = "foo/view";
String dialect = "Dremio";
String sqlText = "select * from world";
IcebergView view = IcebergView.of(ID, path, 1, 123, dialect, sqlText);
ObjectTypes.Content protoTableGlobal = ObjectTypes.Content.newBuilder().setId(ID).setIcebergMetadataPointer(IcebergMetadataPointer.newBuilder().setMetadataLocation(path)).build();
ObjectTypes.Content protoOnRef = ObjectTypes.Content.newBuilder().setId(ID).setIcebergViewState(IcebergViewState.newBuilder().setVersionId(1).setDialect(dialect).setSchemaId(123).setSqlText(sqlText)).build();
ByteString tableGlobalBytes = worker.toStoreGlobalState(view);
ByteString snapshotBytes = worker.toStoreOnReferenceState(view);
Assertions.assertEquals(protoTableGlobal.toByteString(), tableGlobalBytes);
Assertions.assertEquals(protoOnRef.toByteString(), snapshotBytes);
Content deserialized = worker.valueFromStore(snapshotBytes, Optional.of(tableGlobalBytes));
Assertions.assertEquals(view, deserialized);
}
Aggregations