use of org.apache.iceberg.view.View 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.apache.iceberg.view.View 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.apache.iceberg.view.View in project nessie by projectnessie.
the class TestNessieIcebergViews method testCreateView.
@Test
public void testCreateView() throws IOException {
ViewDefinition viewDefinition = ViewDefinition.of(SQL, SCHEMA, CATALOG_NAME, new ArrayList<>());
TableIdentifier viewIdentifier = ViewUtils.toCatalogTableIdentifier(VIEW_IDENTIFIER + "x");
catalog.create(viewIdentifier.toString(), viewDefinition, Collections.emptyMap());
View icebergView = catalog.load(viewIdentifier.toString());
assertThat(icebergView).isNotNull();
assertThat(icebergView.currentVersion().versionId()).isEqualTo(1);
assertThat(icebergView.currentVersion().viewDefinition()).isEqualTo(viewDefinition);
assertThat(Paths.get(metadataLocationViews(viewIdentifier.name()))).exists();
assertThat(metadataFilesForViews(viewIdentifier.name())).isNotNull().hasSize(1);
verifyCommitMetadata();
assertThat(api.getCommitLog().refName(BRANCH).get().getLogEntries()).hasSize(3);
verifyViewInNessie(viewIdentifier, icebergView);
}
Aggregations