Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down