Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaterializeMySQL Engine column comments support #25199

Merged
merged 9 commits into from Jun 17, 2021

Conversation

sand6255
Copy link
Contributor

Implemented MySQL engine column comments support

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
ClickHouse database created with MaterializeMySQL now contains all column comments from the MySQL database that materialized.

Implemented MySQL engine column comments support
@robot-clickhouse robot-clickhouse added doc-alert pr-feature Pull request with new product feature labels Jun 11, 2021
@kssenii kssenii self-assigned this Jun 11, 2021
@kssenii kssenii changed the title MySQL Engine column comments support MaterializeMySQL Engine column comments support Jun 11, 2021
@@ -117,6 +118,37 @@ static inline NamesAndTypesList getColumnsList(ASTExpressionList * columns_defin
return columns_name_and_type;
}

static ColumnsDescription getColumnsDescription(const NamesAndTypesList & columns_name_and_type, const ASTExpressionList * columns_definition)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has the same name as InterpreterCreateQuery::getColumnsDescription, but implementation and purpose is a little different, so It will be better to use a different name to mark the difference.

Comment on lines 123 to 124
if (columns_name_and_type.size() != columns_definition->children.size())
throw Exception("Columns of different size provided.", ErrorCodes::BAD_ARGUMENTS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to rather be LOGICAL_ERROR instead of BAD_ARGUMENTS.
Though columns_name_and_type is initialized with getColumnsList(columns_definition), where columns_name_and_type is created by iterating columns_definition->children, so probably assert(columns_name_and_type.size() == columns_definition->children.size()) is enough. But LOGICAL_ERROR is also ok.

src/Interpreters/MySQL/InterpretersMySQLDDLQuery.cpp Outdated Show resolved Hide resolved
@@ -223,3 +223,15 @@ TEST(MySQLCreateRewritten, UniqueKeysConvert)
std::string(MATERIALIZEMYSQL_TABLE_COLUMNS) +
") ENGINE = ReplacingMergeTree(_version) PARTITION BY intDiv(id, 18446744073709551) ORDER BY (code, name, tenant_id, id)");
}

TEST(MySQLCreateRewritten, QueryWithColumnComments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be you can also make integration test in tests/integration/test_materialize_mysql_database/test.py?

Comment on lines +129 to +133
for (
auto [column_name_and_type, declare_column_ast] = std::tuple{columns_name_and_type.begin(), columns_definition->children.begin()};
column_name_and_type != columns_name_and_type.end();
column_name_and_type++,
declare_column_ast++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little over-complicated given that column_name_and_type was actually initialized as getColumnsList(columns_definition) a few line before call to this getColumnsDescription.

It could be simpler to first create columns_description (by using implementation of getColumnsList plus one check for comment in column_options - there are already such checks for other options so it will be a more correct place for that, and returning columns_description there instead) and then get columns_name_and_type from columns_description->getAllPhysical().

But I think it is also ok to leave your variant if you really want..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was what I tried initially. Problem for this implementation is modifying type in GetKeys (modifyPrimaryKeysToNonNullable) for ColumnsDescription, since there is no good way (or I didn't found it) to change internal ColumnDescription by iterator.
So in my implementation columns_name_and_type is mostly needed to create final types and names for columns, to later initialize descriptions from them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, why there is a problem with getKeys - I was suggesting to only modify getColumnsList to return ColumnsDescription, instead of NameAndTypesList. And on the next line to get columns_with_type_and_name via columns_description->getAllPhysical(). All other methods will still use columns_with_type_and_name. This will simplify the code a lot and there will be no need for getColumnsDescriptionFromList method, which actually does the same thing, which is done in getColumnsList but for other column features.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since getKeys changes columns_with_type_and_name that we generate with getColumnsList, and if we just modify getColumnsList to return ColumnsDescription - we will miss this changes in our descriptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I agree.
By the way, lets rename getColumnsDescriptionFromList -> createColumnsDescription

@sand6255 sand6255 force-pushed the MySQL-column-comments-support branch from 35232df to 46b230d Compare June 16, 2021 06:22
@kssenii
Copy link
Member

kssenii commented Jun 17, 2021

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Jun 17, 2021

Command update: success

Branch has been successfully updated

@kssenii kssenii merged commit f9c0bfb into ClickHouse:master Jun 17, 2021
@sevirov
Copy link
Contributor

sevirov commented Jun 24, 2021

Internal documentation ticket: DOCSUP-10513.

@sand6255 sand6255 deleted the MySQL-column-comments-support branch June 28, 2021 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants