2019-01-14 18:15:04 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserAlterQuery.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
2018-08-07 13:58:11 +00:00
|
|
|
#include <Parsers/ExpressionListParsers.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ParserCreateQuery.h>
|
2017-09-06 20:34:26 +00:00
|
|
|
#include <Parsers/ParserPartition.h>
|
2020-01-29 17:44:16 +00:00
|
|
|
#include <Parsers/ParserSelectWithUnionQuery.h>
|
2019-07-24 15:22:16 +00:00
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTIdentifier.h>
|
2019-02-05 14:50:25 +00:00
|
|
|
#include <Parsers/ASTIndexDeclaration.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTAlterQuery.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
2018-08-07 13:58:11 +00:00
|
|
|
#include <Parsers/ASTAssignment.h>
|
2018-05-21 13:49:54 +00:00
|
|
|
#include <Parsers/parseDatabaseAndTableName.h>
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2013-08-07 13:07:42 +00:00
|
|
|
{
|
2018-06-09 15:53:14 +00:00
|
|
|
auto command = std::make_shared<ASTAlterCommand>();
|
|
|
|
node = command;
|
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_add_column("ADD COLUMN");
|
|
|
|
ParserKeyword s_drop_column("DROP COLUMN");
|
2017-06-22 11:01:30 +00:00
|
|
|
ParserKeyword s_clear_column("CLEAR COLUMN");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_modify_column("MODIFY COLUMN");
|
2020-03-25 18:44:08 +00:00
|
|
|
ParserKeyword s_rename_column("RENAME COLUMN");
|
2018-10-14 15:30:06 +00:00
|
|
|
ParserKeyword s_comment_column("COMMENT COLUMN");
|
2018-10-15 18:47:47 +00:00
|
|
|
ParserKeyword s_modify_order_by("MODIFY ORDER BY");
|
2019-04-15 09:30:45 +00:00
|
|
|
ParserKeyword s_modify_ttl("MODIFY TTL");
|
2020-01-22 13:24:20 +00:00
|
|
|
ParserKeyword s_materialize_ttl("MATERIALIZE TTL");
|
2019-07-24 15:22:16 +00:00
|
|
|
ParserKeyword s_modify_setting("MODIFY SETTING");
|
2020-01-29 17:44:16 +00:00
|
|
|
ParserKeyword s_modify_query("MODIFY QUERY");
|
2017-06-18 03:07:03 +00:00
|
|
|
|
2019-02-05 14:50:25 +00:00
|
|
|
ParserKeyword s_add_index("ADD INDEX");
|
|
|
|
ParserKeyword s_drop_index("DROP INDEX");
|
2019-05-09 14:25:18 +00:00
|
|
|
ParserKeyword s_clear_index("CLEAR INDEX");
|
2019-04-09 15:36:33 +00:00
|
|
|
ParserKeyword s_materialize_index("MATERIALIZE INDEX");
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-06-02 14:41:12 +00:00
|
|
|
ParserKeyword s_add_constraint("ADD CONSTRAINT");
|
|
|
|
ParserKeyword s_drop_constraint("DROP CONSTRAINT");
|
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
ParserKeyword s_add("ADD");
|
|
|
|
ParserKeyword s_drop("DROP");
|
|
|
|
ParserKeyword s_suspend("SUSPEND");
|
|
|
|
ParserKeyword s_resume("RESUME");
|
|
|
|
ParserKeyword s_refresh("REFRESH");
|
|
|
|
ParserKeyword s_modify("MODIFY");
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_attach_partition("ATTACH PARTITION");
|
|
|
|
ParserKeyword s_detach_partition("DETACH PARTITION");
|
|
|
|
ParserKeyword s_drop_partition("DROP PARTITION");
|
2019-08-20 09:59:19 +00:00
|
|
|
ParserKeyword s_move_partition("MOVE PARTITION");
|
2019-07-22 11:23:11 +00:00
|
|
|
ParserKeyword s_drop_detached_partition("DROP DETACHED PARTITION");
|
|
|
|
ParserKeyword s_drop_detached_part("DROP DETACHED PART");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_attach_part("ATTACH PART");
|
2019-07-18 15:19:03 +00:00
|
|
|
ParserKeyword s_move_part("MOVE PART");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_fetch_partition("FETCH PARTITION");
|
2018-10-30 15:04:13 +00:00
|
|
|
ParserKeyword s_replace_partition("REPLACE PARTITION");
|
|
|
|
ParserKeyword s_freeze("FREEZE");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_partition("PARTITION");
|
|
|
|
|
2020-07-01 14:58:52 +00:00
|
|
|
ParserKeyword s_first("FIRST");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_after("AFTER");
|
2018-12-21 14:53:00 +00:00
|
|
|
ParserKeyword s_if_not_exists("IF NOT EXISTS");
|
|
|
|
ParserKeyword s_if_exists("IF EXISTS");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_from("FROM");
|
2017-06-22 11:01:30 +00:00
|
|
|
ParserKeyword s_in_partition("IN PARTITION");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_with("WITH");
|
|
|
|
ParserKeyword s_name("NAME");
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-07-18 15:19:03 +00:00
|
|
|
ParserKeyword s_to_disk("TO DISK");
|
|
|
|
ParserKeyword s_to_volume("TO VOLUME");
|
2019-09-17 11:59:09 +00:00
|
|
|
ParserKeyword s_to_table("TO TABLE");
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2018-02-02 16:02:43 +00:00
|
|
|
ParserKeyword s_delete_where("DELETE WHERE");
|
2018-08-07 13:58:11 +00:00
|
|
|
ParserKeyword s_update("UPDATE");
|
|
|
|
ParserKeyword s_where("WHERE");
|
2020-03-25 18:44:08 +00:00
|
|
|
ParserKeyword s_to("TO");
|
2018-02-02 16:02:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserCompoundIdentifier parser_name;
|
2018-06-09 15:53:14 +00:00
|
|
|
ParserStringLiteral parser_string_literal;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserCompoundColumnDeclaration parser_col_decl;
|
2019-02-05 14:50:25 +00:00
|
|
|
ParserIndexDeclaration parser_idx_decl;
|
2019-06-02 14:41:12 +00:00
|
|
|
ParserConstraintDeclaration parser_constraint_decl;
|
2018-11-14 22:46:39 +00:00
|
|
|
ParserCompoundColumnDeclaration parser_modify_col_decl(false);
|
2017-09-06 20:34:26 +00:00
|
|
|
ParserPartition parser_partition;
|
2018-08-07 13:58:11 +00:00
|
|
|
ParserExpression parser_exp_elem;
|
|
|
|
ParserList parser_assignment_list(
|
|
|
|
std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma),
|
|
|
|
/* allow_empty = */ false);
|
2019-07-24 15:22:16 +00:00
|
|
|
ParserSetQuery parser_settings(true);
|
2019-05-28 21:17:48 +00:00
|
|
|
ParserNameList values_p;
|
2020-01-29 17:44:16 +00:00
|
|
|
ParserSelectWithUnionQuery select_p;
|
2019-10-09 13:02:05 +00:00
|
|
|
ParserTTLExpressionList parser_ttl_list;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (is_live_view)
|
2018-06-09 15:53:14 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_refresh.ignore(pos, expected))
|
2018-06-09 15:53:14 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::LIVE_VIEW_REFRESH;
|
2018-06-09 15:53:14 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else
|
2017-04-21 12:39:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else
|
2018-06-09 15:53:14 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_add_column.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (s_if_not_exists.ignore(pos, expected))
|
|
|
|
command->if_not_exists = true;
|
2018-12-21 14:53:00 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_col_decl.parse(pos, command->col_decl, expected))
|
|
|
|
return false;
|
2017-04-21 12:39:28 +00:00
|
|
|
|
2020-07-01 14:58:52 +00:00
|
|
|
if (s_first.ignore(pos, expected))
|
|
|
|
command->first = true;
|
|
|
|
else if (s_after.ignore(pos, expected))
|
2019-05-28 21:17:48 +00:00
|
|
|
{
|
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::ADD_COLUMN;
|
|
|
|
}
|
2020-03-25 18:44:08 +00:00
|
|
|
else if (s_rename_column.ignore(pos, expected))
|
|
|
|
{
|
2020-04-03 12:26:57 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
2020-04-03 16:33:25 +00:00
|
|
|
command->if_exists = true;
|
2020-03-25 18:44:08 +00:00
|
|
|
|
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!s_to.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!parser_name.parse(pos, command->rename_to, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
command->type = ASTAlterCommand::RENAME_COLUMN;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_drop_partition.ignore(pos, expected))
|
2019-05-09 14:25:18 +00:00
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_PARTITION;
|
2019-05-09 14:25:18 +00:00
|
|
|
}
|
2019-08-22 20:38:58 +00:00
|
|
|
else if (s_drop_detached_partition.ignore(pos, expected))
|
2019-02-05 14:50:25 +00:00
|
|
|
{
|
2019-08-22 20:38:58 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2019-02-05 14:50:25 +00:00
|
|
|
return false;
|
2019-08-22 20:38:58 +00:00
|
|
|
|
|
|
|
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
|
2019-02-05 14:50:25 +00:00
|
|
|
}
|
2019-08-22 20:38:58 +00:00
|
|
|
else if (s_drop_detached_part.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_string_literal.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-08-22 20:38:58 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
|
|
|
|
command->part = true;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_drop_column.ignore(pos, expected))
|
2019-08-16 10:55:40 +00:00
|
|
|
{
|
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
|
|
|
return false;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-08-22 20:38:58 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_COLUMN;
|
|
|
|
command->detach = false;
|
2019-08-16 10:55:40 +00:00
|
|
|
}
|
|
|
|
else if (s_clear_column.ignore(pos, expected))
|
2019-02-05 14:50:25 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2018-12-21 14:53:00 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
2019-02-05 14:50:25 +00:00
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_COLUMN;
|
2019-08-16 10:55:40 +00:00
|
|
|
command->clear_column = true;
|
2019-05-28 21:17:48 +00:00
|
|
|
command->detach = false;
|
2018-06-09 15:53:14 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
if (s_in_partition.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
}
|
|
|
|
else if (s_add_index.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_if_not_exists.ignore(pos, expected))
|
|
|
|
command->if_not_exists = true;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_idx_decl.parse(pos, command->index_decl, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_after.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_name.parse(pos, command->index, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::ADD_INDEX;
|
2017-06-18 03:07:03 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_drop_index.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2019-04-09 15:36:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_name.parse(pos, command->index, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_INDEX;
|
|
|
|
command->detach = false;
|
2017-06-18 03:07:03 +00:00
|
|
|
}
|
2019-08-16 10:55:40 +00:00
|
|
|
else if (s_clear_index.ignore(pos, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
if (!parser_name.parse(pos, command->index, expected))
|
2019-05-28 21:17:48 +00:00
|
|
|
return false;
|
2018-06-09 15:53:14 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_INDEX;
|
|
|
|
command->clear_index = true;
|
|
|
|
command->detach = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
if (!s_in_partition.ignore(pos, expected))
|
|
|
|
return false;
|
2018-06-09 15:53:14 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2017-06-22 11:01:30 +00:00
|
|
|
}
|
2019-08-16 10:55:40 +00:00
|
|
|
else if (s_materialize_index.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2017-06-22 11:01:30 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
if (!parser_name.parse(pos, command->index, expected))
|
|
|
|
return false;
|
2017-06-22 11:01:30 +00:00
|
|
|
|
2019-08-16 10:55:40 +00:00
|
|
|
command->type = ASTAlterCommand::MATERIALIZE_INDEX;
|
2019-05-28 21:17:48 +00:00
|
|
|
command->detach = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_in_partition.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 10:09:29 +00:00
|
|
|
else if (s_move_part.ignore(pos, expected))
|
2019-08-27 08:54:21 +00:00
|
|
|
{
|
2019-08-21 10:09:29 +00:00
|
|
|
if (!parser_string_literal.parse(pos, command->partition, expected))
|
2019-08-27 08:54:21 +00:00
|
|
|
return false;
|
2019-07-26 08:42:17 +00:00
|
|
|
|
2019-08-21 10:09:29 +00:00
|
|
|
command->type = ASTAlterCommand::MOVE_PARTITION;
|
|
|
|
command->part = true;
|
2019-08-20 09:59:19 +00:00
|
|
|
|
2019-08-21 10:09:29 +00:00
|
|
|
if (s_to_disk.ignore(pos))
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::DISK;
|
2019-08-21 10:09:29 +00:00
|
|
|
else if (s_to_volume.ignore(pos))
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::VOLUME;
|
2019-09-17 11:59:09 +00:00
|
|
|
else if (s_to_table.ignore(pos))
|
|
|
|
{
|
|
|
|
if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table))
|
|
|
|
return false;
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::TABLE;
|
2019-09-17 11:59:09 +00:00
|
|
|
}
|
2019-08-21 10:09:29 +00:00
|
|
|
else
|
2019-08-27 08:54:21 +00:00
|
|
|
return false;
|
2019-07-26 08:42:17 +00:00
|
|
|
|
2020-05-22 13:29:33 +00:00
|
|
|
if (command->move_destination_type != DataDestinationType::TABLE)
|
2019-09-16 07:27:38 +00:00
|
|
|
{
|
|
|
|
ASTPtr ast_space_name;
|
|
|
|
if (!parser_string_literal.parse(pos, ast_space_name, expected))
|
|
|
|
return false;
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2019-09-16 07:27:38 +00:00
|
|
|
command->move_destination_name = ast_space_name->as<ASTLiteral &>().value.get<const String &>();
|
|
|
|
}
|
2019-08-21 10:09:29 +00:00
|
|
|
}
|
|
|
|
else if (s_move_partition.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2019-08-27 08:54:21 +00:00
|
|
|
return false;
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2019-08-27 08:54:21 +00:00
|
|
|
command->type = ASTAlterCommand::MOVE_PARTITION;
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2019-08-21 10:09:29 +00:00
|
|
|
if (s_to_disk.ignore(pos))
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::DISK;
|
2019-08-21 10:09:29 +00:00
|
|
|
else if (s_to_volume.ignore(pos))
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::VOLUME;
|
2019-09-17 11:59:09 +00:00
|
|
|
else if (s_to_table.ignore(pos))
|
2019-09-16 07:27:38 +00:00
|
|
|
{
|
2019-09-17 11:59:09 +00:00
|
|
|
if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table))
|
|
|
|
return false;
|
2020-05-22 13:29:33 +00:00
|
|
|
command->move_destination_type = DataDestinationType::TABLE;
|
2019-09-16 07:27:38 +00:00
|
|
|
}
|
2019-08-21 10:09:29 +00:00
|
|
|
else
|
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2020-05-22 13:29:33 +00:00
|
|
|
if (command->move_destination_type != DataDestinationType::TABLE)
|
2019-09-16 07:27:38 +00:00
|
|
|
{
|
|
|
|
ASTPtr ast_space_name;
|
|
|
|
if (!parser_string_literal.parse(pos, ast_space_name, expected))
|
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-09-16 07:27:38 +00:00
|
|
|
command->move_destination_name = ast_space_name->as<ASTLiteral &>().value.get<const String &>();
|
|
|
|
}
|
2019-08-27 08:54:21 +00:00
|
|
|
}
|
2019-08-21 03:33:08 +00:00
|
|
|
else if (s_add_constraint.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-08-21 03:33:08 +00:00
|
|
|
if (s_if_not_exists.ignore(pos, expected))
|
|
|
|
command->if_not_exists = true;
|
2019-07-26 08:42:17 +00:00
|
|
|
|
2019-08-21 03:33:08 +00:00
|
|
|
if (!parser_constraint_decl.parse(pos, command->constraint_decl, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
return false;
|
2014-08-07 11:46:01 +00:00
|
|
|
|
2019-08-21 03:33:08 +00:00
|
|
|
command->type = ASTAlterCommand::ADD_CONSTRAINT;
|
2017-06-18 03:07:03 +00:00
|
|
|
}
|
2019-08-21 03:33:08 +00:00
|
|
|
else if (s_drop_constraint.ignore(pos, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2019-08-21 03:33:08 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-08-21 03:33:08 +00:00
|
|
|
if (!parser_name.parse(pos, command->constraint, expected))
|
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-08-21 03:33:08 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_CONSTRAINT;
|
|
|
|
command->detach = false;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_detach_partition.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::DROP_PARTITION;
|
|
|
|
command->detach = true;
|
2017-06-18 03:07:03 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_attach_partition.ignore(pos, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2018-10-30 15:04:13 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_from.ignore(pos))
|
|
|
|
{
|
|
|
|
if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
command->replace = false;
|
|
|
|
command->type = ASTAlterCommand::REPLACE_PARTITION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command->type = ASTAlterCommand::ATTACH_PARTITION;
|
|
|
|
}
|
2018-11-01 13:55:49 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_replace_partition.ignore(pos, expected))
|
2018-11-01 13:55:49 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
2014-08-07 11:46:01 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!s_from.ignore(pos, expected))
|
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table))
|
|
|
|
return false;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->replace = true;
|
|
|
|
command->type = ASTAlterCommand::REPLACE_PARTITION;
|
2018-10-30 15:04:13 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_attach_part.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_string_literal.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->part = true;
|
|
|
|
command->type = ASTAlterCommand::ATTACH_PARTITION;
|
|
|
|
}
|
|
|
|
else if (s_fetch_partition.ignore(pos, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2018-10-30 15:04:13 +00:00
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!s_from.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
ASTPtr ast_from;
|
|
|
|
if (!parser_string_literal.parse(pos, ast_from, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2014-10-09 20:28:33 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->from = ast_from->as<ASTLiteral &>().value.get<const String &>();
|
|
|
|
command->type = ASTAlterCommand::FETCH_PARTITION;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_freeze.ignore(pos, expected))
|
2018-11-01 13:55:49 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_partition.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
command->type = ASTAlterCommand::FREEZE_PARTITION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command->type = ASTAlterCommand::FREEZE_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// WITH NAME 'name' - place local backup to directory with specified name
|
|
|
|
if (s_with.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!s_name.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ASTPtr ast_with_name;
|
|
|
|
if (!parser_string_literal.parse(pos, ast_with_name, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
command->with_name = ast_with_name->as<ASTLiteral &>().value.get<const String &>();
|
|
|
|
}
|
2018-10-30 15:04:13 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_modify_column.ignore(pos, expected))
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2019-05-28 21:17:48 +00:00
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2018-12-21 14:53:00 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_modify_col_decl.parse(pos, command->col_decl, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2016-06-28 20:50:37 +00:00
|
|
|
|
2020-07-01 14:58:52 +00:00
|
|
|
if (s_first.ignore(pos, expected))
|
|
|
|
command->first = true;
|
|
|
|
else if (s_after.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::MODIFY_COLUMN;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else if (s_modify_order_by.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_exp_elem.parse(pos, command->order_by, expected))
|
|
|
|
return false;
|
2018-10-15 18:47:47 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::MODIFY_ORDER_BY;
|
|
|
|
}
|
|
|
|
else if (s_delete_where.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_exp_elem.parse(pos, command->predicate, expected))
|
|
|
|
return false;
|
2016-05-17 20:11:43 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::DELETE;
|
|
|
|
}
|
|
|
|
else if (s_update.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_assignment_list.parse(pos, command->update_assignments, expected))
|
|
|
|
return false;
|
2018-08-07 13:58:11 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!s_where.ignore(pos, expected))
|
|
|
|
return false;
|
2018-08-07 13:58:11 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_exp_elem.parse(pos, command->predicate, expected))
|
|
|
|
return false;
|
2018-08-07 13:58:11 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::UPDATE;
|
|
|
|
}
|
|
|
|
else if (s_comment_column.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (s_if_exists.ignore(pos, expected))
|
|
|
|
command->if_exists = true;
|
2018-12-21 14:53:00 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_name.parse(pos, command->column, expected))
|
|
|
|
return false;
|
2018-10-14 15:30:06 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
if (!parser_string_literal.parse(pos, command->comment, expected))
|
|
|
|
return false;
|
2018-10-14 15:30:06 +00:00
|
|
|
|
2019-05-28 21:17:48 +00:00
|
|
|
command->type = ASTAlterCommand::COMMENT_COLUMN;
|
|
|
|
}
|
|
|
|
else if (s_modify_ttl.ignore(pos, expected))
|
|
|
|
{
|
2019-10-09 13:02:05 +00:00
|
|
|
if (!parser_ttl_list.parse(pos, command->ttl, expected))
|
2019-05-28 21:17:48 +00:00
|
|
|
return false;
|
|
|
|
command->type = ASTAlterCommand::MODIFY_TTL;
|
|
|
|
}
|
2020-01-22 13:24:20 +00:00
|
|
|
else if (s_materialize_ttl.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
command->type = ASTAlterCommand::MATERIALIZE_TTL;
|
2020-03-10 11:17:26 +00:00
|
|
|
|
|
|
|
if (s_in_partition.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_partition.parse(pos, command->partition, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-22 13:24:20 +00:00
|
|
|
}
|
2019-08-21 08:57:19 +00:00
|
|
|
else if (s_modify_setting.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!parser_settings.parse(pos, command->settings_changes, expected))
|
|
|
|
return false;
|
|
|
|
command->type = ASTAlterCommand::MODIFY_SETTING;
|
|
|
|
}
|
2020-01-29 17:44:16 +00:00
|
|
|
else if (s_modify_query.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!select_p.parse(pos, command->select, expected))
|
|
|
|
return false;
|
|
|
|
command->type = ASTAlterCommand::MODIFY_QUERY;
|
|
|
|
}
|
2019-05-28 21:17:48 +00:00
|
|
|
else
|
2019-04-15 09:30:45 +00:00
|
|
|
return false;
|
2018-10-14 15:30:06 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
2016-05-17 20:11:43 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
if (command->col_decl)
|
|
|
|
command->children.push_back(command->col_decl);
|
|
|
|
if (command->column)
|
|
|
|
command->children.push_back(command->column);
|
|
|
|
if (command->partition)
|
|
|
|
command->children.push_back(command->partition);
|
2018-12-20 18:57:20 +00:00
|
|
|
if (command->order_by)
|
|
|
|
command->children.push_back(command->order_by);
|
2018-06-09 15:53:14 +00:00
|
|
|
if (command->predicate)
|
|
|
|
command->children.push_back(command->predicate);
|
2018-08-07 13:58:11 +00:00
|
|
|
if (command->update_assignments)
|
|
|
|
command->children.push_back(command->update_assignments);
|
2019-05-28 21:17:48 +00:00
|
|
|
if (command->values)
|
|
|
|
command->children.push_back(command->values);
|
2018-12-20 18:57:20 +00:00
|
|
|
if (command->comment)
|
|
|
|
command->children.push_back(command->comment);
|
2019-04-15 09:30:45 +00:00
|
|
|
if (command->ttl)
|
|
|
|
command->children.push_back(command->ttl);
|
2019-08-21 08:57:19 +00:00
|
|
|
if (command->settings_changes)
|
|
|
|
command->children.push_back(command->settings_changes);
|
2016-05-05 18:28:46 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-02-02 16:02:43 +00:00
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool ParserAlterCommandList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
auto command_list = std::make_shared<ASTAlterCommandList>();
|
|
|
|
node = command_list;
|
|
|
|
|
|
|
|
ParserToken s_comma(TokenType::Comma);
|
2019-08-23 05:08:06 +00:00
|
|
|
ParserAlterCommand p_command(is_live_view);
|
2018-06-09 15:53:14 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ASTPtr command;
|
|
|
|
if (!p_command.parse(pos, command, expected))
|
|
|
|
return false;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
command_list->add(command);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2018-06-09 15:53:14 +00:00
|
|
|
while (s_comma.ignore(pos, expected));
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-07 13:58:11 +00:00
|
|
|
bool ParserAssignment::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
auto assignment = std::make_shared<ASTAssignment>();
|
|
|
|
node = assignment;
|
|
|
|
|
|
|
|
ParserIdentifier p_identifier;
|
|
|
|
ParserToken s_equals(TokenType::Equals);
|
|
|
|
ParserExpression p_expression;
|
|
|
|
|
|
|
|
ASTPtr column;
|
|
|
|
if (!p_identifier.parse(pos, column, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!s_equals.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!p_expression.parse(pos, assignment->expression, expected))
|
|
|
|
return false;
|
|
|
|
|
2019-08-08 20:02:30 +00:00
|
|
|
tryGetIdentifierNameInto(column, assignment->column_name);
|
2018-08-07 13:58:11 +00:00
|
|
|
if (assignment->expression)
|
|
|
|
assignment->children.push_back(assignment->expression);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
bool ParserAlterQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
auto query = std::make_shared<ASTAlterQuery>();
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
ParserKeyword s_alter_table("ALTER TABLE");
|
2019-05-28 21:17:48 +00:00
|
|
|
ParserKeyword s_alter_live_view("ALTER LIVE VIEW");
|
|
|
|
|
|
|
|
bool is_live_view = false;
|
|
|
|
|
2018-06-09 15:53:14 +00:00
|
|
|
if (!s_alter_table.ignore(pos, expected))
|
2019-05-28 21:17:48 +00:00
|
|
|
{
|
|
|
|
if (!s_alter_live_view.ignore(pos, expected))
|
2019-08-23 05:08:06 +00:00
|
|
|
return false;
|
2019-05-28 21:17:48 +00:00
|
|
|
else
|
|
|
|
is_live_view = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_live_view)
|
|
|
|
query->is_live_view = true;
|
2018-06-09 15:53:14 +00:00
|
|
|
|
|
|
|
if (!parseDatabaseAndTableName(pos, expected, query->database, query->table))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
String cluster_str;
|
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
query->cluster = cluster_str;
|
|
|
|
|
2019-08-23 05:08:06 +00:00
|
|
|
ParserAlterCommandList p_command_list(is_live_view);
|
2018-06-09 15:53:14 +00:00
|
|
|
ASTPtr command_list;
|
|
|
|
if (!p_command_list.parse(pos, command_list, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
query->set(query->command_list, command_list);
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2013-08-07 13:07:42 +00:00
|
|
|
}
|
2018-08-07 13:58:11 +00:00
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
}
|