Merge pull request #25781 from sand6255/MaterializeMySQL-Engine-column-comments-improvement

MaterializeMySQL: Improved column comments support
This commit is contained in:
Kseniia Sumarokova 2021-06-28 21:57:24 +03:00 committed by GitHub
commit d9c46003cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -582,7 +582,8 @@ ASTs InterpreterAlterImpl::getRewrittenQueries(
if (alter_command->type == MySQLParser::ASTAlterCommand::ADD_COLUMN) if (alter_command->type == MySQLParser::ASTAlterCommand::ADD_COLUMN)
{ {
const auto & additional_columns_name_and_type = getColumnsList(alter_command->additional_columns); const auto & additional_columns_name_and_type = getColumnsList(alter_command->additional_columns);
const auto & additional_columns = InterpreterCreateQuery::formatColumns(additional_columns_name_and_type); const auto & additional_columns_description = createColumnsDescription(additional_columns_name_and_type, alter_command->additional_columns);
const auto & additional_columns = InterpreterCreateQuery::formatColumns(additional_columns_description);
for (size_t index = 0; index < additional_columns_name_and_type.size(); ++index) for (size_t index = 0; index < additional_columns_name_and_type.size(); ++index)
{ {
@ -676,7 +677,8 @@ ASTs InterpreterAlterImpl::getRewrittenQueries(
if (!alter_command->old_name.empty()) if (!alter_command->old_name.empty())
modify_columns.front().name = alter_command->old_name; modify_columns.front().name = alter_command->old_name;
rewritten_command->col_decl = InterpreterCreateQuery::formatColumns(modify_columns)->children[0]; const auto & modify_columns_description = createColumnsDescription(modify_columns, alter_command->additional_columns);
rewritten_command->col_decl = InterpreterCreateQuery::formatColumns(modify_columns_description)->children[0];
if (!alter_command->column_name.empty()) if (!alter_command->column_name.empty())
{ {

View File

@ -850,6 +850,10 @@ def materialize_with_column_comments_test(clickhouse_node, mysql_node, service_n
mysql_node.query("CREATE TABLE materialize_with_column_comments_test.test (id int NOT NULL PRIMARY KEY, value VARCHAR(255) COMMENT 'test comment') ENGINE=InnoDB") mysql_node.query("CREATE TABLE materialize_with_column_comments_test.test (id int NOT NULL PRIMARY KEY, value VARCHAR(255) COMMENT 'test comment') ENGINE=InnoDB")
clickhouse_node.query("CREATE DATABASE materialize_with_column_comments_test ENGINE = MaterializeMySQL('{}:3306', 'materialize_with_column_comments_test', 'root', 'clickhouse')".format(service_name)) clickhouse_node.query("CREATE DATABASE materialize_with_column_comments_test ENGINE = MaterializeMySQL('{}:3306', 'materialize_with_column_comments_test', 'root', 'clickhouse')".format(service_name))
check_query(clickhouse_node, "DESCRIBE TABLE materialize_with_column_comments_test.test", "id\tInt32\t\t\t\t\t\nvalue\tNullable(String)\t\t\ttest comment\t\t\n_sign\tInt8\tMATERIALIZED\t1\t\t\t\n_version\tUInt64\tMATERIALIZED\t1\t\t\t\n") check_query(clickhouse_node, "DESCRIBE TABLE materialize_with_column_comments_test.test", "id\tInt32\t\t\t\t\t\nvalue\tNullable(String)\t\t\ttest comment\t\t\n_sign\tInt8\tMATERIALIZED\t1\t\t\t\n_version\tUInt64\tMATERIALIZED\t1\t\t\t\n")
mysql_node.query("ALTER TABLE materialize_with_column_comments_test.test MODIFY value VARCHAR(255) COMMENT 'comment test'")
check_query(clickhouse_node, "DESCRIBE TABLE materialize_with_column_comments_test.test", "id\tInt32\t\t\t\t\t\nvalue\tNullable(String)\t\t\tcomment test\t\t\n_sign\tInt8\tMATERIALIZED\t1\t\t\t\n_version\tUInt64\tMATERIALIZED\t1\t\t\t\n")
mysql_node.query("ALTER TABLE materialize_with_column_comments_test.test ADD value2 int COMMENT 'test comment 2'")
check_query(clickhouse_node, "DESCRIBE TABLE materialize_with_column_comments_test.test", "id\tInt32\t\t\t\t\t\nvalue\tNullable(String)\t\t\tcomment test\t\t\nvalue2\tNullable(Int32)\t\t\ttest comment 2\t\t\n_sign\tInt8\tMATERIALIZED\t1\t\t\t\n_version\tUInt64\tMATERIALIZED\t1\t\t\t\n")
clickhouse_node.query("DROP DATABASE materialize_with_column_comments_test") clickhouse_node.query("DROP DATABASE materialize_with_column_comments_test")
mysql_node.query("DROP DATABASE materialize_with_column_comments_test") mysql_node.query("DROP DATABASE materialize_with_column_comments_test")