Search in sources :

Example 1 with View

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);
}
Also used : CommentUpdate(org.apache.iceberg.view.CommentUpdate) Schema(org.apache.iceberg.Schema) View(org.apache.iceberg.view.View) IcebergView(org.projectnessie.model.IcebergView) Test(org.junit.jupiter.api.Test)

Example 2 with View

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);
}
Also used : HashMap(java.util.HashMap) Schema(org.apache.iceberg.Schema) ViewDefinition(org.apache.iceberg.view.ViewDefinition) ArrayList(java.util.ArrayList) View(org.apache.iceberg.view.View) IcebergView(org.projectnessie.model.IcebergView) Test(org.junit.jupiter.api.Test)

Example 3 with View

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);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) ViewDefinition(org.apache.iceberg.view.ViewDefinition) View(org.apache.iceberg.view.View) IcebergView(org.projectnessie.model.IcebergView) Test(org.junit.jupiter.api.Test)

Aggregations

View (org.apache.iceberg.view.View)3 Test (org.junit.jupiter.api.Test)3 IcebergView (org.projectnessie.model.IcebergView)3 Schema (org.apache.iceberg.Schema)2 ViewDefinition (org.apache.iceberg.view.ViewDefinition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)1 CommentUpdate (org.apache.iceberg.view.CommentUpdate)1