Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for comment on view in blackhole connector #18516

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/main/sphinx/connector/blackhole.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ additional features:
- {doc}`/sql/create-table`
- {doc}`/sql/create-table-as`
- {doc}`/sql/drop-table`
- {doc}`/sql/comment`
- {doc}`/sql/create-schema`
- {doc}`/sql/drop-schema`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ private void checkSchemaExists(String schemaName)
}
}

@Override
public void setViewComment(ConnectorSession session, SchemaTableName viewName, Optional<String> comment)
{
ConnectorViewDefinition view = getView(session, viewName).orElseThrow(() -> new ViewNotFoundException(viewName));
views.put(viewName, new ConnectorViewDefinition(
view.getOriginalSql(),
view.getCatalog(),
view.getSchema(),
view.getColumns(),
comment,
view.getOwner(),
view.isRunAsInvoker()));
}

@Override
public void setViewColumnComment(ConnectorSession session, SchemaTableName viewName, String columnName, Optional<String> comment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@ public void dataGenerationUsage()
assertThatQueryDoesNotReturnValues("DROP TABLE nation");
}

@Test
public void testCreateViewWithComment()
{
String viewName = "test_crerate_view_with_comment_" + randomNameSuffix();
queryRunner.execute("CREATE VIEW " + viewName + " COMMENT 'test comment' AS SELECT * FROM tpch.tiny.nation");

assertThat(getTableComment(viewName)).isEqualTo("test comment");

queryRunner.execute("DROP VIEW " + viewName);
}

@Test
public void testCommentOnView()
{
String viewName = "test_comment_on_view_" + randomNameSuffix();
queryRunner.execute("CREATE VIEW " + viewName + " AS SELECT * FROM tpch.tiny.nation");

// comment set
queryRunner.execute("COMMENT ON VIEW " + viewName + " IS 'new comment'");
assertThat(getTableComment(viewName)).isEqualTo("new comment");

// comment deleted
queryRunner.execute("COMMENT ON VIEW " + viewName + " IS NULL");
assertThat(getTableComment(viewName)).isEqualTo(null);

// comment set to non-empty value before verifying setting empty comment
queryRunner.execute("COMMENT ON VIEW " + viewName + " IS 'updated comment'");
assertThat(getTableComment(viewName)).isEqualTo("updated comment");

// comment set to empty
queryRunner.execute("COMMENT ON VIEW " + viewName + " IS ''");
assertThat(getTableComment(viewName)).isEqualTo("");

queryRunner.execute("DROP VIEW " + viewName);
}

private String getTableComment(String tableName)
{
return (String) queryRunner.execute("SELECT comment FROM system.metadata.table_comments " +
"WHERE catalog_name = CURRENT_CATALOG AND schema_name = CURRENT_SCHEMA AND table_name = '" + tableName + "'")
.getOnlyValue();
}

@Test
public void testMaterializedView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ public void testCommentView()
String viewName = "comment_view" + randomNameSuffix();
assertUpdate("CREATE VIEW " + viewName + " COMMENT 'old comment' AS SELECT * FROM orders");
assertAccessDenied("COMMENT ON VIEW " + viewName + " IS 'new comment'", "Cannot comment view to .*", privilege(viewName, COMMENT_VIEW));
assertThatThrownBy(() -> getQueryRunner().execute(getSession(), "COMMENT ON VIEW " + viewName + " IS 'new comment'"))
.hasMessageContaining("This connector does not support setting view comments");
assertAccessAllowed("COMMENT ON VIEW " + viewName + " IS 'new comment'");
}

@Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse")
Expand Down