2018-06-13 13:49:27 +00:00
|
|
|
#include <Storages/PartitionCommands.h>
|
|
|
|
#include <Storages/IStorage.h>
|
2019-11-20 08:06:51 +00:00
|
|
|
#include <Storages/MergeTree/PartDestinationType.h>
|
2018-06-13 13:49:27 +00:00
|
|
|
#include <Parsers/ASTAlterQuery.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
std::optional<PartitionCommand> PartitionCommand::parse(const ASTAlterCommand * command_ast)
|
|
|
|
{
|
|
|
|
if (command_ast->type == ASTAlterCommand::DROP_PARTITION)
|
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = DROP_PARTITION;
|
|
|
|
res.partition = command_ast->partition;
|
|
|
|
res.detach = command_ast->detach;
|
|
|
|
return res;
|
|
|
|
}
|
2019-07-22 11:23:11 +00:00
|
|
|
else if (command_ast->type == ASTAlterCommand::DROP_DETACHED_PARTITION)
|
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = DROP_DETACHED_PARTITION;
|
|
|
|
res.partition = command_ast->partition;
|
|
|
|
res.part = command_ast->part;
|
|
|
|
return res;
|
|
|
|
}
|
2018-06-13 13:49:27 +00:00
|
|
|
else if (command_ast->type == ASTAlterCommand::ATTACH_PARTITION)
|
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = ATTACH_PARTITION;
|
|
|
|
res.partition = command_ast->partition;
|
|
|
|
res.part = command_ast->part;
|
|
|
|
return res;
|
|
|
|
}
|
2019-07-18 15:19:03 +00:00
|
|
|
else if (command_ast->type == ASTAlterCommand::MOVE_PARTITION)
|
2018-06-13 13:49:27 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
2019-07-18 15:19:03 +00:00
|
|
|
res.type = MOVE_PARTITION;
|
2018-06-13 13:49:27 +00:00
|
|
|
res.partition = command_ast->partition;
|
2019-07-18 15:19:03 +00:00
|
|
|
res.part = command_ast->part;
|
2019-07-23 09:38:26 +00:00
|
|
|
switch (command_ast->move_destination_type)
|
2019-07-18 15:19:03 +00:00
|
|
|
{
|
2019-11-20 08:06:51 +00:00
|
|
|
case PartDestinationType::DISK:
|
2019-07-23 13:34:17 +00:00
|
|
|
res.move_destination_type = PartitionCommand::MoveDestinationType::DISK;
|
2019-07-18 15:19:03 +00:00
|
|
|
break;
|
2019-11-20 08:06:51 +00:00
|
|
|
case PartDestinationType::VOLUME:
|
2019-07-23 13:34:17 +00:00
|
|
|
res.move_destination_type = PartitionCommand::MoveDestinationType::VOLUME;
|
2019-07-18 15:19:03 +00:00
|
|
|
break;
|
2019-12-17 07:06:41 +00:00
|
|
|
case PartDestinationType::TABLE:
|
2019-09-17 11:59:09 +00:00
|
|
|
res.move_destination_type = PartitionCommand::MoveDestinationType::TABLE;
|
2019-09-16 07:27:38 +00:00
|
|
|
res.to_database = command_ast->to_database;
|
|
|
|
res.to_table = command_ast->to_table;
|
2019-12-17 07:06:41 +00:00
|
|
|
break;
|
2019-10-09 13:02:05 +00:00
|
|
|
default:
|
2019-09-16 07:27:38 +00:00
|
|
|
break;
|
2019-07-18 15:19:03 +00:00
|
|
|
}
|
2019-09-17 11:59:09 +00:00
|
|
|
if (res.move_destination_type != PartitionCommand::MoveDestinationType::TABLE)
|
2019-09-16 07:27:38 +00:00
|
|
|
res.move_destination_name = command_ast->move_destination_name;
|
2018-06-13 13:49:27 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else if (command_ast->type == ASTAlterCommand::REPLACE_PARTITION)
|
2019-07-26 08:42:17 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
2018-06-13 13:49:27 +00:00
|
|
|
res.type = REPLACE_PARTITION;
|
2019-07-26 08:42:17 +00:00
|
|
|
res.partition = command_ast->partition;
|
2018-06-13 13:49:27 +00:00
|
|
|
res.replace = command_ast->replace;
|
|
|
|
res.from_database = command_ast->from_database;
|
|
|
|
res.from_table = command_ast->from_table;
|
2019-07-26 08:42:17 +00:00
|
|
|
return res;
|
|
|
|
}
|
2018-06-13 13:49:27 +00:00
|
|
|
else if (command_ast->type == ASTAlterCommand::FETCH_PARTITION)
|
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = FETCH_PARTITION;
|
|
|
|
res.partition = command_ast->partition;
|
|
|
|
res.from_zookeeper_path = command_ast->from;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else if (command_ast->type == ASTAlterCommand::FREEZE_PARTITION)
|
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = FREEZE_PARTITION;
|
|
|
|
res.partition = command_ast->partition;
|
|
|
|
res.with_name = command_ast->with_name;
|
|
|
|
return res;
|
|
|
|
}
|
2018-11-20 17:05:22 +00:00
|
|
|
else if (command_ast->type == ASTAlterCommand::FREEZE_ALL)
|
|
|
|
{
|
|
|
|
PartitionCommand command;
|
|
|
|
command.type = PartitionCommand::FREEZE_ALL_PARTITIONS;
|
|
|
|
command.with_name = command_ast->with_name;
|
|
|
|
return command;
|
|
|
|
}
|
2018-06-13 13:49:27 +00:00
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
2020-03-17 17:22:41 +00:00
|
|
|
|
2018-06-13 13:49:27 +00:00
|
|
|
}
|