Fix some bugs

This commit is contained in:
alesapin 2019-07-24 18:22:16 +03:00
parent 8a00ce5ff1
commit f7e0d17490
4 changed files with 14 additions and 4 deletions

View File

@ -5,6 +5,7 @@
#include <Parsers/ExpressionListParsers.h> #include <Parsers/ExpressionListParsers.h>
#include <Parsers/ParserCreateQuery.h> #include <Parsers/ParserCreateQuery.h>
#include <Parsers/ParserPartition.h> #include <Parsers/ParserPartition.h>
#include <Parsers/ParserSetQuery.h>
#include <Parsers/ASTIdentifier.h> #include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTIndexDeclaration.h> #include <Parsers/ASTIndexDeclaration.h>
#include <Parsers/ASTAlterQuery.h> #include <Parsers/ASTAlterQuery.h>
@ -28,6 +29,7 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
ParserKeyword s_comment_column("COMMENT COLUMN"); ParserKeyword s_comment_column("COMMENT COLUMN");
ParserKeyword s_modify_order_by("MODIFY ORDER BY"); ParserKeyword s_modify_order_by("MODIFY ORDER BY");
ParserKeyword s_modify_ttl("MODIFY TTL"); ParserKeyword s_modify_ttl("MODIFY TTL");
ParserKeyword s_modify_setting("MODIFY SETTING");
ParserKeyword s_add_index("ADD INDEX"); ParserKeyword s_add_index("ADD INDEX");
ParserKeyword s_drop_index("DROP INDEX"); ParserKeyword s_drop_index("DROP INDEX");
@ -63,6 +65,7 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
ParserList parser_assignment_list( ParserList parser_assignment_list(
std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma), std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma),
/* allow_empty = */ false); /* allow_empty = */ false);
ParserSetQuery parser_settings(true);
if (s_add_column.ignore(pos, expected)) if (s_add_column.ignore(pos, expected))
{ {
@ -289,6 +292,12 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
return false; return false;
command->type = ASTAlterCommand::MODIFY_TTL; command->type = ASTAlterCommand::MODIFY_TTL;
} }
else if (s_modify_setting.ignore(pos, expected))
{
if (!parser_settings.parse(pos, command->settings_changes, expected))
return false;
command->type = ASTAlterCommand::MODIFY_SETTING;
}
else else
return false; return false;

View File

@ -13,6 +13,7 @@ namespace DB
* [CLEAR COLUMN [IF EXISTS] col_to_clear [IN PARTITION partition],] * [CLEAR COLUMN [IF EXISTS] col_to_clear [IN PARTITION partition],]
* [MODIFY COLUMN [IF EXISTS] col_to_modify type, ...] * [MODIFY COLUMN [IF EXISTS] col_to_modify type, ...]
* [MODIFY PRIMARY KEY (a, b, c...)] * [MODIFY PRIMARY KEY (a, b, c...)]
* [MODIFY SETTING setting_name=setting_value, ...]
* [COMMENT COLUMN [IF EXISTS] col_name string] * [COMMENT COLUMN [IF EXISTS] col_name string]
* [DROP|DETACH|ATTACH PARTITION|PART partition, ...] * [DROP|DETACH|ATTACH PARTITION|PART partition, ...]
* [FETCH PARTITION partition FROM ...] * [FETCH PARTITION partition FROM ...]

View File

@ -317,7 +317,7 @@ void AlterCommand::apply(ColumnsDescription & columns_description, IndicesDescri
} }
else if (type == MODIFY_SETTING) else if (type == MODIFY_SETTING)
{ {
changes.insert(changes.begin(), settings_changes.begin(), settings_changes.end()); changes.insert(changes.end(), settings_changes.begin(), settings_changes.end());
} }
else else
throw Exception("Wrong parameter type in ALTER query", ErrorCodes::LOGICAL_ERROR); throw Exception("Wrong parameter type in ALTER query", ErrorCodes::LOGICAL_ERROR);
@ -344,7 +344,7 @@ void AlterCommands::apply(ColumnsDescription & columns_description, IndicesDescr
for (const AlterCommand & command : *this) for (const AlterCommand & command : *this)
if (!command.ignore) if (!command.ignore)
command.apply(new_columns_description, new_indices_description, new_order_by_ast, new_primary_key_ast, new_ttl_table_ast, changes); command.apply(new_columns_description, new_indices_description, new_order_by_ast, new_primary_key_ast, new_ttl_table_ast, new_changes);
columns_description = std::move(new_columns_description); columns_description = std::move(new_columns_description);
indices_description = std::move(new_indices_description); indices_description = std::move(new_indices_description);

View File

@ -256,10 +256,10 @@ void StorageMergeTree::alter(
{ {
auto & storage_ast = ast.as<ASTStorage &>(); auto & storage_ast = ast.as<ASTStorage &>();
if (!new_changes.empty()) if (!new_changes.empty())
storage_ast.settings->changes.insert(storage_ast.settings->changes.begin(), new_changes.begin(), new_changes.end()); storage_ast.settings->changes.insert(storage_ast.settings->changes.end(), new_changes.begin(), new_changes.end());
}; };
context.getDatabase(current_database_name)->alterTable(context, current_table_name, new_columns, new_indices, {}); context.getDatabase(current_database_name)->alterTable(context, current_table_name, new_columns, new_indices, storage_modifier);
setColumns(std::move(new_columns)); setColumns(std::move(new_columns));
settings.applyChanges(new_changes); settings.applyChanges(new_changes);
return; return;