diff --git a/docs/src/main/sphinx/connector/blackhole.md b/docs/src/main/sphinx/connector/blackhole.md index 1f514b88cd52..37bd63fa6de4 100644 --- a/docs/src/main/sphinx/connector/blackhole.md +++ b/docs/src/main/sphinx/connector/blackhole.md @@ -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` diff --git a/plugin/trino-blackhole/src/main/java/io/trino/plugin/blackhole/BlackHoleMetadata.java b/plugin/trino-blackhole/src/main/java/io/trino/plugin/blackhole/BlackHoleMetadata.java index 679c8450c88e..08c092977eaf 100644 --- a/plugin/trino-blackhole/src/main/java/io/trino/plugin/blackhole/BlackHoleMetadata.java +++ b/plugin/trino-blackhole/src/main/java/io/trino/plugin/blackhole/BlackHoleMetadata.java @@ -398,6 +398,20 @@ private void checkSchemaExists(String schemaName) } } + @Override + public void setViewComment(ConnectorSession session, SchemaTableName viewName, Optional 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 comment) { diff --git a/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java b/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java index 56a68e5bd255..4b65cfe6a623 100644 --- a/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java +++ b/plugin/trino-blackhole/src/test/java/io/trino/plugin/blackhole/TestBlackHoleSmoke.java @@ -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() { diff --git a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java index fc9c2757e4cc..5b7b04f29c26 100644 --- a/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java +++ b/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java @@ -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")