mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Copy comment when using CREATE AS statement
This commit is contained in:
parent
6b9b597051
commit
3d7c1db763
@ -20,7 +20,7 @@ namespace
|
|||||||
/// If this is a definition of a system table we'll remove columns and comment because they're redundant for backups.
|
/// If this is a definition of a system table we'll remove columns and comment because they're redundant for backups.
|
||||||
auto & create = data.create_query->as<ASTCreateQuery &>();
|
auto & create = data.create_query->as<ASTCreateQuery &>();
|
||||||
create.reset(create.columns_list);
|
create.reset(create.columns_list);
|
||||||
create.reset(create.comment);
|
create.comment.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitStorageReplicatedTableEngine(ASTStorage & storage, const DDLAdjustingForBackupVisitor::Data & data)
|
void visitStorageReplicatedTableEngine(ASTStorage & storage, const DDLAdjustingForBackupVisitor::Data & data)
|
||||||
|
@ -192,7 +192,7 @@ ASTPtr DatabaseFilesystem::getCreateDatabaseQuery() const
|
|||||||
if (const auto database_comment = getDatabaseComment(); !database_comment.empty())
|
if (const auto database_comment = getDatabaseComment(); !database_comment.empty())
|
||||||
{
|
{
|
||||||
auto & ast_create_query = ast->as<ASTCreateQuery &>();
|
auto & ast_create_query = ast->as<ASTCreateQuery &>();
|
||||||
ast_create_query.set(ast_create_query.comment, std::make_shared<ASTLiteral>(database_comment));
|
ast_create_query.comment = std::make_shared<ASTLiteral>(database_comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast;
|
return ast;
|
||||||
|
@ -107,7 +107,7 @@ ASTPtr DatabaseMemory::getCreateDatabaseQuery() const
|
|||||||
create_query->storage->set(create_query->storage->engine, engine);
|
create_query->storage->set(create_query->storage->engine, engine);
|
||||||
|
|
||||||
if (const auto comment_value = getDatabaseComment(); !comment_value.empty())
|
if (const auto comment_value = getDatabaseComment(); !comment_value.empty())
|
||||||
create_query->set(create_query->comment, std::make_shared<ASTLiteral>(comment_value));
|
create_query->comment = std::make_shared<ASTLiteral>(comment_value);
|
||||||
|
|
||||||
return create_query;
|
return create_query;
|
||||||
}
|
}
|
||||||
|
@ -535,7 +535,7 @@ ASTPtr DatabaseOnDisk::getCreateDatabaseQuery() const
|
|||||||
if (const auto database_comment = getDatabaseComment(); !database_comment.empty())
|
if (const auto database_comment = getDatabaseComment(); !database_comment.empty())
|
||||||
{
|
{
|
||||||
auto & ast_create_query = ast->as<ASTCreateQuery &>();
|
auto & ast_create_query = ast->as<ASTCreateQuery &>();
|
||||||
ast_create_query.set(ast_create_query.comment, std::make_shared<ASTLiteral>(database_comment));
|
ast_create_query.comment = std::make_shared<ASTLiteral>(database_comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast;
|
return ast;
|
||||||
@ -784,8 +784,7 @@ ASTPtr DatabaseOnDisk::getCreateQueryFromStorage(const String & table_name, cons
|
|||||||
static_cast<unsigned>(settings.max_parser_backtracks),
|
static_cast<unsigned>(settings.max_parser_backtracks),
|
||||||
throw_on_error);
|
throw_on_error);
|
||||||
|
|
||||||
create_table_query->set(create_table_query->as<ASTCreateQuery>()->comment,
|
create_table_query->as<ASTCreateQuery>()->comment = std::make_shared<ASTLiteral>("SYSTEM TABLE is built on the fly.");
|
||||||
std::make_shared<ASTLiteral>("SYSTEM TABLE is built on the fly."));
|
|
||||||
|
|
||||||
return create_table_query;
|
return create_table_query;
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ void applyMetadataChangesToCreateQuery(const ASTPtr & query, const StorageInMemo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (metadata.comment.empty())
|
if (metadata.comment.empty())
|
||||||
ast_create_query.reset(ast_create_query.comment);
|
ast_create_query.comment.reset();
|
||||||
else
|
else
|
||||||
ast_create_query.set(ast_create_query.comment, std::make_shared<ASTLiteral>(metadata.comment));
|
ast_create_query.comment = std::make_shared<ASTLiteral>(metadata.comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -785,6 +785,9 @@ InterpreterCreateQuery::TableProperties InterpreterCreateQuery::getTableProperti
|
|||||||
auto as_storage_metadata = as_storage->getInMemoryMetadataPtr();
|
auto as_storage_metadata = as_storage->getInMemoryMetadataPtr();
|
||||||
properties.columns = as_storage_metadata->getColumns();
|
properties.columns = as_storage_metadata->getColumns();
|
||||||
|
|
||||||
|
if (!create.comment)
|
||||||
|
create.comment = std::make_shared<ASTLiteral>(Field(as_storage_metadata->comment));
|
||||||
|
|
||||||
/// Secondary indices and projections make sense only for MergeTree family of storage engines.
|
/// Secondary indices and projections make sense only for MergeTree family of storage engines.
|
||||||
/// We should not copy them for other storages.
|
/// We should not copy them for other storages.
|
||||||
if (create.storage && endsWith(create.storage->engine->name, "MergeTree"))
|
if (create.storage && endsWith(create.storage->engine->name, "MergeTree"))
|
||||||
|
@ -656,7 +656,7 @@ ASTPtr SystemLog<LogElement>::getCreateTableQuery()
|
|||||||
StorageWithComment & storage_with_comment = storage_with_comment_ast->as<StorageWithComment &>();
|
StorageWithComment & storage_with_comment = storage_with_comment_ast->as<StorageWithComment &>();
|
||||||
|
|
||||||
create->set(create->storage, storage_with_comment.storage);
|
create->set(create->storage, storage_with_comment.storage);
|
||||||
create->set(create->comment, storage_with_comment.comment);
|
create->comment = storage_with_comment.comment;
|
||||||
|
|
||||||
/// Write additional (default) settings for MergeTree engine to make it make it possible to compare ASTs
|
/// Write additional (default) settings for MergeTree engine to make it make it possible to compare ASTs
|
||||||
/// and recreate tables on settings changes.
|
/// and recreate tables on settings changes.
|
||||||
|
@ -255,7 +255,7 @@ ASTPtr ASTCreateQuery::clone() const
|
|||||||
if (as_table_function)
|
if (as_table_function)
|
||||||
res->set(res->as_table_function, as_table_function->clone());
|
res->set(res->as_table_function, as_table_function->clone());
|
||||||
if (comment)
|
if (comment)
|
||||||
res->set(res->comment, comment->clone());
|
res->comment = comment->clone();
|
||||||
|
|
||||||
cloneOutputOptions(*res);
|
cloneOutputOptions(*res);
|
||||||
cloneTableOptions(*res);
|
cloneTableOptions(*res);
|
||||||
|
@ -112,7 +112,7 @@ public:
|
|||||||
String as_table;
|
String as_table;
|
||||||
IAST * as_table_function = nullptr;
|
IAST * as_table_function = nullptr;
|
||||||
ASTSelectWithUnionQuery * select = nullptr;
|
ASTSelectWithUnionQuery * select = nullptr;
|
||||||
IAST * comment = nullptr;
|
ASTPtr comment = nullptr;
|
||||||
ASTPtr sql_security = nullptr;
|
ASTPtr sql_security = nullptr;
|
||||||
|
|
||||||
ASTTableOverrideList * table_overrides = nullptr; /// For CREATE DATABASE with engines that automatically create tables
|
ASTTableOverrideList * table_overrides = nullptr; /// For CREATE DATABASE with engines that automatically create tables
|
||||||
|
@ -861,7 +861,7 @@ bool ParserCreateTableQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
query->set(query->as_table_function, as_table_function);
|
query->set(query->as_table_function, as_table_function);
|
||||||
|
|
||||||
if (comment)
|
if (comment)
|
||||||
query->set(query->comment, comment);
|
query->comment = comment;
|
||||||
|
|
||||||
if (query->columns_list && query->columns_list->primary_key)
|
if (query->columns_list && query->columns_list->primary_key)
|
||||||
{
|
{
|
||||||
@ -1012,8 +1012,7 @@ bool ParserCreateLiveViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
|||||||
query->set(query->select, select);
|
query->set(query->select, select);
|
||||||
|
|
||||||
if (comment)
|
if (comment)
|
||||||
query->set(query->comment, comment);
|
query->comment = comment;
|
||||||
|
|
||||||
if (sql_security)
|
if (sql_security)
|
||||||
query->sql_security = typeid_cast<std::shared_ptr<ASTSQLSecurity>>(sql_security);
|
query->sql_security = typeid_cast<std::shared_ptr<ASTSQLSecurity>>(sql_security);
|
||||||
|
|
||||||
@ -1414,7 +1413,8 @@ bool ParserCreateDatabaseQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
|||||||
|
|
||||||
query->set(query->storage, storage);
|
query->set(query->storage, storage);
|
||||||
if (comment)
|
if (comment)
|
||||||
query->set(query->comment, comment);
|
query->comment = comment;
|
||||||
|
|
||||||
if (table_overrides && !table_overrides->children.empty())
|
if (table_overrides && !table_overrides->children.empty())
|
||||||
query->set(query->table_overrides, table_overrides);
|
query->set(query->table_overrides, table_overrides);
|
||||||
|
|
||||||
@ -1617,7 +1617,7 @@ bool ParserCreateViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
|||||||
if (refresh_strategy)
|
if (refresh_strategy)
|
||||||
query->set(query->refresh_strategy, refresh_strategy);
|
query->set(query->refresh_strategy, refresh_strategy);
|
||||||
if (comment)
|
if (comment)
|
||||||
query->set(query->comment, comment);
|
query->comment = comment;
|
||||||
if (sql_security)
|
if (sql_security)
|
||||||
query->sql_security = typeid_cast<std::shared_ptr<ASTSQLSecurity>>(sql_security);
|
query->sql_security = typeid_cast<std::shared_ptr<ASTSQLSecurity>>(sql_security);
|
||||||
|
|
||||||
@ -1794,7 +1794,7 @@ bool ParserCreateDictionaryQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, E
|
|||||||
query->cluster = cluster_str;
|
query->cluster = cluster_str;
|
||||||
|
|
||||||
if (comment)
|
if (comment)
|
||||||
query->set(query->comment, comment);
|
query->comment = comment;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
original comment
|
||||||
|
original comment
|
||||||
|
new comment
|
11
tests/queries/0_stateless/03033_create_as_copies_comment.sql
Normal file
11
tests/queries/0_stateless/03033_create_as_copies_comment.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
DROP TABLE IF EXISTS base;
|
||||||
|
DROP TABLE IF EXISTS copy_without_comment;
|
||||||
|
DROP TABLE IF EXISTS copy_with_comment;
|
||||||
|
|
||||||
|
CREATE TABLE base (a Int32) ENGINE = MergeTree ORDER BY a COMMENT 'original comment';
|
||||||
|
CREATE TABLE copy_without_comment as base;
|
||||||
|
CREATE TABLE copy_with_comment as base COMMENT 'new comment';
|
||||||
|
|
||||||
|
SELECT comment FROM system.tables WHERE name = 'base';
|
||||||
|
SELECT comment FROM system.tables WHERE name = 'copy_without_comment';
|
||||||
|
SELECT comment FROM system.tables WHERE name = 'copy_with_comment';
|
Loading…
Reference in New Issue
Block a user