diff --git a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java index 9db003fbcecc..f8b2e61b2bcb 100644 --- a/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java +++ b/plugin/trino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseClient.java @@ -377,6 +377,9 @@ protected String getColumnDefinitionSql(ConnectorSession session, ColumnMetadata // By default, the clickhouse column is not allowed to be null sb.append(toWriteMapping(session, column.getType()).getDataType()); } + if (column.getComment() != null) { + sb.append(format(" COMMENT '%s'", column.getComment())); + } return sb.toString(); } @@ -401,9 +404,6 @@ protected String renameSchemaSql(String remoteSchemaName, String newRemoteSchema @Override public void addColumn(ConnectorSession session, JdbcTableHandle handle, ColumnMetadata column) { - if (column.getComment() != null) { - throw new TrinoException(NOT_SUPPORTED, "This connector does not support adding columns with comments"); - } try (Connection connection = connectionFactory.openConnection(session)) { String remoteColumnName = getIdentifierMapping().toRemoteColumnName(connection, column.getName()); String sql = format( diff --git a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java index 20ce36f55ab1..0e11f86d498e 100644 --- a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java +++ b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/TestClickHouseConnectorTest.java @@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; public class TestClickHouseConnectorTest @@ -178,7 +179,16 @@ public void testAddColumn() @Override public void testAddColumnWithComment() { - throw new SkipException("Clickhouse connector does not support specifying a comment when adding a column"); + // Override because the default storage type doesn't support adding columns + try (TestTable table = new TestTable(getQueryRunner()::execute, "test_add_col_desc_", "(a_varchar varchar NOT NULL) WITH (engine = 'MergeTree', order_by = ARRAY['a_varchar'])")) { + String tableName = table.getName(); + + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN b_varchar varchar COMMENT 'test new column comment'"); + assertThat(getColumnComment(tableName, "b_varchar")).isEqualTo("test new column comment"); + + assertUpdate("ALTER TABLE " + tableName + " ADD COLUMN empty_comment varchar COMMENT ''"); + assertNull(getColumnComment(tableName, "empty_comment")); + } } @Test @@ -233,6 +243,15 @@ 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() {