From 2f12b2a7a66ffabd5afb6f8037a1a6956ab5d0c6 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Wed, 18 May 2022 18:45:00 +0900 Subject: [PATCH] Deny creating tables with column comment if unsupported --- .../accumulo/TestAccumuloConnectorTest.java | 17 +++++++++++++++++ .../io/trino/plugin/jdbc/BaseJdbcClient.java | 3 +++ .../plugin/jdbc/TestJdbcConnectorTest.java | 1 + .../plugin/bigquery/BigQueryMetadata.java | 3 +++ .../bigquery/TestBigQueryConnectorTest.java | 1 + .../plugin/cassandra/CassandraMetadata.java | 3 +++ .../cassandra/TestCassandraConnectorTest.java | 1 + .../BaseClickHouseConnectorTest.java | 9 --------- .../plugin/deltalake/DeltaLakeMetadata.java | 4 ++++ .../BaseDeltaLakeMinioConnectorTest.java | 1 + .../io/trino/plugin/kudu/KuduMetadata.java | 3 +++ .../kudu/AbstractKuduConnectorTest.java | 16 ++++++++++++++++ .../mariadb/BaseMariaDbConnectorTest.java | 1 + .../trino/plugin/memory/MemoryMetadata.java | 3 +++ .../memory/TestMemoryConnectorTest.java | 1 + .../mongodb/BaseMongoConnectorTest.java | 12 ------------ .../plugin/mysql/BaseMySqlConnectorTest.java | 1 + .../oracle/BaseOracleConnectorTest.java | 1 + .../trino/plugin/phoenix/PhoenixClient.java | 3 +++ .../phoenix/TestPhoenixConnectorTest.java | 1 + .../trino/plugin/phoenix5/PhoenixClient.java | 3 +++ .../phoenix5/TestPhoenixConnectorTest.java | 1 + .../TestPostgreSqlConnectorTest.java | 1 + .../plugin/raptor/legacy/RaptorMetadata.java | 3 +++ .../legacy/BaseRaptorConnectorTest.java | 1 + .../TestSingleStoreConnectorTest.java | 1 + .../sqlserver/BaseSqlServerConnectorTest.java | 1 + .../io/trino/testing/BaseConnectorTest.java | 19 +++++++++++++++++++ .../testing/TestingConnectorBehavior.java | 1 + 29 files changed, 95 insertions(+), 21 deletions(-) diff --git a/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java b/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java index 1c108b17b78a..9549f9e7649f 100644 --- a/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java +++ b/plugin/trino-accumulo/src/test/java/io/trino/plugin/accumulo/TestAccumuloConnectorTest.java @@ -29,6 +29,7 @@ import static io.trino.plugin.accumulo.AccumuloQueryRunner.createAccumuloQueryRunner; import static io.trino.spi.type.VarcharType.VARCHAR; import static io.trino.testing.MaterializedResult.resultBuilder; +import static io.trino.testing.sql.TestTable.randomTableSuffix; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; @@ -98,6 +99,22 @@ protected TestTable createTableWithDefaultColumns() throw new SkipException("Accumulo connector does not support column default values"); } + @Override + public void testCreateTableWithColumnComment() + { + // TODO Avoid setting hard-coded column comment + // Accumulo connector ignores specified comment and sets column comments as + // "Accumulo row ID" for the first column when "row_id" table property isn't specified + // "Accumulo column %s:%s. Indexed: boolean" for other columns + String tableName = "test_create_" + randomTableSuffix(); + assertUpdate("CREATE TABLE " + tableName + " (a bigint COMMENT 'test comment a', b bigint COMMENT 'test comment b')"); + + assertEquals(getColumnComment(tableName, "a"), "Accumulo row ID"); + assertEquals(getColumnComment(tableName, "b"), "Accumulo column b:b. Indexed: false"); + + assertUpdate("DROP TABLE " + tableName); + } + @Override public void testCreateTableAsSelect() { diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java index 0c6063b14013..10adeb6e3c26 100644 --- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java +++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java @@ -549,6 +549,9 @@ protected String createTableSql(RemoteTableName remoteTableName, List co protected String getColumnDefinitionSql(ConnectorSession session, ColumnMetadata column, String columnName) { + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } StringBuilder sb = new StringBuilder() .append(quoted(columnName)) .append(" ") diff --git a/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestJdbcConnectorTest.java b/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestJdbcConnectorTest.java index 5cc211a85b61..b521ba2e46b6 100644 --- a/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestJdbcConnectorTest.java +++ b/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/TestJdbcConnectorTest.java @@ -67,6 +67,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: diff --git a/plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryMetadata.java b/plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryMetadata.java index 4f49a1f289e7..06797938c3ce 100644 --- a/plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryMetadata.java +++ b/plugin/trino-bigquery/src/main/java/io/trino/plugin/bigquery/BigQueryMetadata.java @@ -375,6 +375,9 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe if (tableMetadata.getComment().isPresent()) { throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment"); } + if (tableMetadata.getColumns().stream().anyMatch(column -> column.getComment() != null)) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } try { createTable(session, tableMetadata); } diff --git a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryConnectorTest.java b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryConnectorTest.java index 63659840d546..671bdd067fb7 100644 --- a/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryConnectorTest.java +++ b/plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/TestBigQueryConnectorTest.java @@ -70,6 +70,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) case SUPPORTS_NOT_NULL_CONSTRAINT: case SUPPORTS_CREATE_TABLE_WITH_DATA: case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_DELETE: case SUPPORTS_INSERT: case SUPPORTS_ADD_COLUMN: diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java index 289f54aed946..a961cd110c78 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java @@ -296,6 +296,9 @@ private CassandraOutputTableHandle createTable(ConnectorTableMetadata tableMetad ImmutableList.Builder columnExtra = ImmutableList.builder(); columnExtra.add(new ExtraColumnMetadata(ID_COLUMN_NAME, true)); for (ColumnMetadata column : tableMetadata.getColumns()) { + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } columnNames.add(column.getName()); columnTypes.add(column.getType()); columnExtra.add(new ExtraColumnMetadata(column.getName(), column.isHidden())); diff --git a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/TestCassandraConnectorTest.java b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/TestCassandraConnectorTest.java index 18c5f24d47df..fc1f3023866e 100644 --- a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/TestCassandraConnectorTest.java +++ b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/TestCassandraConnectorTest.java @@ -96,6 +96,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: return false; case SUPPORTS_RENAME_TABLE: diff --git a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java index 73b3dd66aec9..15c10214350a 100644 --- a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java +++ b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java @@ -231,15 +231,6 @@ protected TestTable createTableWithDefaultColumns() "col_required2 Int64) ENGINE=Log"); } - @Test - public void testCreateTableWithColumnComment() - { - // TODO (https://github.com/trinodb/trino/issues/11162) Merge into BaseConnectorTest - try (TestTable table = new TestTable(getQueryRunner()::execute, "test_column_comment", "(col integer COMMENT 'column comment')")) { - assertEquals(getColumnComment(table.getName(), "col"), "column comment"); - } - } - @Override public void testCharVarcharComparison() { diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java index f0a218432f9f..413e8bb72742 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java @@ -583,6 +583,10 @@ public void dropSchema(ConnectorSession session, String schemaName) @Override public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) { + if (tableMetadata.getColumns().stream().anyMatch(column -> column.getComment() != null)) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } + SchemaTableName schemaTableName = tableMetadata.getTable(); String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java index 48fad77d4110..f54ecb86e5b8 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java @@ -107,6 +107,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) case SUPPORTS_AGGREGATION_PUSHDOWN: case SUPPORTS_RENAME_TABLE: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_DROP_COLUMN: case SUPPORTS_RENAME_COLUMN: case SUPPORTS_COMMENT_ON_TABLE: diff --git a/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KuduMetadata.java b/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KuduMetadata.java index a352f06f23fd..a6db1993923d 100755 --- a/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KuduMetadata.java +++ b/plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KuduMetadata.java @@ -250,6 +250,9 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe if (tableMetadata.getComment().isPresent()) { throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with table comment"); } + if (tableMetadata.getColumns().stream().anyMatch(column -> column.getComment() != null)) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } clientSession.createTable(tableMetadata, ignoreExisting); } diff --git a/plugin/trino-kudu/src/test/java/io/trino/plugin/kudu/AbstractKuduConnectorTest.java b/plugin/trino-kudu/src/test/java/io/trino/plugin/kudu/AbstractKuduConnectorTest.java index defd869c8cda..0c8446eee2e7 100644 --- a/plugin/trino-kudu/src/test/java/io/trino/plugin/kudu/AbstractKuduConnectorTest.java +++ b/plugin/trino-kudu/src/test/java/io/trino/plugin/kudu/AbstractKuduConnectorTest.java @@ -276,6 +276,22 @@ public void testCreateTable() throw new SkipException("TODO"); } + @Override + public void testCreateTableWithColumnComment() + { + // TODO https://github.com/trinodb/trino/issues/12469 Support column comment when creating tables + String tableName = "test_create_" + randomTableSuffix(); + + assertQueryFails( + "CREATE TABLE " + tableName + "(" + + "id INT WITH (primary_key=true)," + + "a VARCHAR COMMENT 'test comment')" + + "WITH (partition_by_hash_columns = ARRAY['id'], partition_by_hash_buckets = 2)", + "This connector does not support creating tables with column comment"); + + assertUpdate("DROP TABLE IF EXISTS " + tableName); + } + @Override public void testDropTable() { diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java index 5e128fb478e0..38e43430eccc 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java @@ -43,6 +43,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) case SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV: case SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE: return true; + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: case SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN: case SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM: diff --git a/plugin/trino-memory/src/main/java/io/trino/plugin/memory/MemoryMetadata.java b/plugin/trino-memory/src/main/java/io/trino/plugin/memory/MemoryMetadata.java index cd0f44aeb09f..d6dac74bb3f7 100644 --- a/plugin/trino-memory/src/main/java/io/trino/plugin/memory/MemoryMetadata.java +++ b/plugin/trino-memory/src/main/java/io/trino/plugin/memory/MemoryMetadata.java @@ -248,6 +248,9 @@ public synchronized MemoryOutputTableHandle beginCreateTable(ConnectorSession se ImmutableList.Builder columns = ImmutableList.builder(); for (int i = 0; i < tableMetadata.getColumns().size(); i++) { ColumnMetadata column = tableMetadata.getColumns().get(i); + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } columns.add(new ColumnInfo(new MemoryColumnHandle(i), column.getName(), column.getType())); } diff --git a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java index 09db864f8b12..6c96241fa7fe 100644 --- a/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java +++ b/plugin/trino-memory/src/test/java/io/trino/plugin/memory/TestMemoryConnectorTest.java @@ -98,6 +98,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: return false; diff --git a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/BaseMongoConnectorTest.java b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/BaseMongoConnectorTest.java index 2a71ee5583d9..e2104ececf38 100644 --- a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/BaseMongoConnectorTest.java +++ b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/BaseMongoConnectorTest.java @@ -135,18 +135,6 @@ public Object[][] guessFieldTypesProvider() }; } - @Test - public void testCreateTableWithColumnComment() - { - // TODO (https://github.com/trinodb/trino/issues/11162) Merge into io.trino.testing.BaseConnectorTest#testCommentColumn - try (TestTable table = new TestTable(getQueryRunner()::execute, "test_column_comment", "(col integer COMMENT 'test')")) { - assertThat((String) computeScalar("SHOW CREATE TABLE " + table.getName())) - .isEqualTo(format("CREATE TABLE %s.%s.%s (\n" + - " col integer COMMENT 'test'\n" + - ")", getSession().getCatalog().orElseThrow(), getSession().getSchema().orElseThrow(), table.getName())); - } - } - @Test public void createTableWithEveryType() { diff --git a/plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java b/plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java index 4e8cf3945f63..199a1c6cd433 100644 --- a/plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java +++ b/plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java @@ -64,6 +64,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_COMMENT_ON_COLUMN: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: return false; diff --git a/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java b/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java index 733b6b81145c..d864a80ddee1 100644 --- a/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java +++ b/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java @@ -67,6 +67,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) case SUPPORTS_COMMENT_ON_TABLE: return false; + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: return false; diff --git a/plugin/trino-phoenix/src/main/java/io/trino/plugin/phoenix/PhoenixClient.java b/plugin/trino-phoenix/src/main/java/io/trino/plugin/phoenix/PhoenixClient.java index 7b2864c209a1..16b8da900bf1 100644 --- a/plugin/trino-phoenix/src/main/java/io/trino/plugin/phoenix/PhoenixClient.java +++ b/plugin/trino-phoenix/src/main/java/io/trino/plugin/phoenix/PhoenixClient.java @@ -607,6 +607,9 @@ public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, Connecto rowkeyColumn = Optional.of(ROWKEY); } for (ColumnMetadata column : tableColumns) { + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } String columnName = getIdentifierMapping().toRemoteColumnName(connection, column.getName()); columnNames.add(columnName); columnTypes.add(column.getType()); diff --git a/plugin/trino-phoenix/src/test/java/io/trino/plugin/phoenix/TestPhoenixConnectorTest.java b/plugin/trino-phoenix/src/test/java/io/trino/plugin/phoenix/TestPhoenixConnectorTest.java index 2fdf20e3b73b..8d4a7be1f842 100644 --- a/plugin/trino-phoenix/src/test/java/io/trino/plugin/phoenix/TestPhoenixConnectorTest.java +++ b/plugin/trino-phoenix/src/test/java/io/trino/plugin/phoenix/TestPhoenixConnectorTest.java @@ -72,6 +72,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: diff --git a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java index caa049cf9591..505513fa973b 100644 --- a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java +++ b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java @@ -599,6 +599,9 @@ public JdbcOutputTableHandle beginCreateTable(ConnectorSession session, Connecto rowkeyColumn = Optional.of(ROWKEY); } for (ColumnMetadata column : tableColumns) { + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } String columnName = getIdentifierMapping().toRemoteColumnName(connection, column.getName()); columnNames.add(columnName); columnTypes.add(column.getType()); diff --git a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java index acf256c4c979..0169b600a79d 100644 --- a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java +++ b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java @@ -90,6 +90,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: diff --git a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java index 06a68035e2fc..f2f55ba1472b 100644 --- a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java +++ b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java @@ -119,6 +119,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return true; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: return false; diff --git a/plugin/trino-raptor-legacy/src/main/java/io/trino/plugin/raptor/legacy/RaptorMetadata.java b/plugin/trino-raptor-legacy/src/main/java/io/trino/plugin/raptor/legacy/RaptorMetadata.java index 9f9e611c3bd5..c5cda14f7bb9 100644 --- a/plugin/trino-raptor-legacy/src/main/java/io/trino/plugin/raptor/legacy/RaptorMetadata.java +++ b/plugin/trino-raptor-legacy/src/main/java/io/trino/plugin/raptor/legacy/RaptorMetadata.java @@ -568,6 +568,9 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con long columnId = 1; for (ColumnMetadata column : tableMetadata.getColumns()) { + if (column.getComment() != null) { + throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating tables with column comment"); + } columnHandles.add(new RaptorColumnHandle(column.getName(), columnId, column.getType())); columnTypes.add(column.getType()); columnId++; diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java index b1356409f7f0..4a60e5b2abc7 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/BaseRaptorConnectorTest.java @@ -75,6 +75,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) case SUPPORTS_CREATE_SCHEMA: case SUPPORTS_RENAME_SCHEMA: case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: diff --git a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java index 14279cfc97a4..7f069c084f3e 100644 --- a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java +++ b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java @@ -80,6 +80,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: case SUPPORTS_COMMENT_ON_TABLE: case SUPPORTS_COMMENT_ON_COLUMN: case SUPPORTS_ADD_COLUMN_WITH_COMMENT: diff --git a/plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/BaseSqlServerConnectorTest.java b/plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/BaseSqlServerConnectorTest.java index 7c8dae460edb..3e8bc143a40b 100644 --- a/plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/BaseSqlServerConnectorTest.java +++ b/plugin/trino-sqlserver/src/test/java/io/trino/plugin/sqlserver/BaseSqlServerConnectorTest.java @@ -72,6 +72,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) return false; case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT: + case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT: return false; case SUPPORTS_COMMENT_ON_TABLE: diff --git a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java index 94a7def8999c..81f941259275 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java @@ -82,6 +82,7 @@ import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_MATERIALIZED_VIEW; import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_SCHEMA; import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE; +import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT; import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE_WITH_DATA; import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT; import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_VIEW; @@ -1910,6 +1911,24 @@ public void testCreateTableWithTableComment() assertUpdate("DROP TABLE " + tableName); } + @Test + public void testCreateTableWithColumnComment() + { + skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE)); + + String tableName = "test_create_" + randomTableSuffix(); + + if (!hasBehavior(SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT)) { + assertQueryFails("CREATE TABLE " + tableName + " (a bigint COMMENT 'test comment')", "This connector does not support creating tables with column comment"); + return; + } + + assertUpdate("CREATE TABLE " + tableName + " (a bigint COMMENT 'test comment')"); + assertEquals(getColumnComment(tableName, "a"), "test comment"); + + assertUpdate("DROP TABLE " + tableName); + } + @Test public void testCreateTableSchemaNotFound() { diff --git a/testing/trino-testing/src/main/java/io/trino/testing/TestingConnectorBehavior.java b/testing/trino-testing/src/main/java/io/trino/testing/TestingConnectorBehavior.java index 40cb810eaaa9..455054b32a3a 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/TestingConnectorBehavior.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/TestingConnectorBehavior.java @@ -55,6 +55,7 @@ public enum TestingConnectorBehavior SUPPORTS_CREATE_TABLE, SUPPORTS_CREATE_TABLE_WITH_DATA(SUPPORTS_CREATE_TABLE), SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT(SUPPORTS_CREATE_TABLE), + SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT(SUPPORTS_CREATE_TABLE), SUPPORTS_RENAME_TABLE, SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS(SUPPORTS_RENAME_TABLE),