2018-06-13 13:49:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Field.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2018-06-13 13:49:27 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
|
|
|
|
2018-06-16 02:16:19 +00:00
|
|
|
#include <optional>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <vector>
|
2018-06-13 13:49:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ASTAlterCommand;
|
|
|
|
|
2020-07-29 08:32:52 +00:00
|
|
|
class Pipe;
|
|
|
|
|
2018-06-13 13:49:27 +00:00
|
|
|
struct PartitionCommand
|
|
|
|
{
|
|
|
|
enum Type
|
|
|
|
{
|
2021-05-08 15:20:40 +00:00
|
|
|
UNKNOWN,
|
|
|
|
|
2018-06-13 13:49:27 +00:00
|
|
|
ATTACH_PARTITION,
|
2019-07-18 15:19:03 +00:00
|
|
|
MOVE_PARTITION,
|
2018-11-01 10:35:50 +00:00
|
|
|
DROP_PARTITION,
|
2019-07-22 11:23:11 +00:00
|
|
|
DROP_DETACHED_PARTITION,
|
2018-06-13 13:49:27 +00:00
|
|
|
FETCH_PARTITION,
|
2018-11-20 17:05:22 +00:00
|
|
|
FREEZE_ALL_PARTITIONS,
|
2018-06-13 13:49:27 +00:00
|
|
|
FREEZE_PARTITION,
|
2021-03-02 20:28:42 +00:00
|
|
|
UNFREEZE_ALL_PARTITIONS,
|
|
|
|
UNFREEZE_PARTITION,
|
2018-11-01 10:35:50 +00:00
|
|
|
REPLACE_PARTITION,
|
2018-06-13 13:49:27 +00:00
|
|
|
};
|
|
|
|
|
2021-05-08 15:20:40 +00:00
|
|
|
Type type = UNKNOWN;
|
2018-06-13 13:49:27 +00:00
|
|
|
|
|
|
|
ASTPtr partition;
|
|
|
|
|
|
|
|
/// true for DETACH PARTITION.
|
|
|
|
bool detach = false;
|
|
|
|
|
2019-07-22 11:23:11 +00:00
|
|
|
/// true for ATTACH PART and DROP DETACHED PART (and false for PARTITION)
|
2018-06-13 13:49:27 +00:00
|
|
|
bool part = false;
|
|
|
|
|
|
|
|
/// For ATTACH PARTITION partition FROM db.table
|
|
|
|
String from_database;
|
|
|
|
String from_table;
|
|
|
|
bool replace = true;
|
|
|
|
|
2019-07-26 10:26:23 +00:00
|
|
|
/// For MOVE PARTITION
|
|
|
|
String to_database;
|
|
|
|
String to_table;
|
2019-07-29 03:14:53 +00:00
|
|
|
|
2018-06-13 13:49:27 +00:00
|
|
|
/// For FETCH PARTITION - path in ZK to the shard, from which to download the partition.
|
|
|
|
String from_zookeeper_path;
|
|
|
|
|
2021-02-24 14:26:46 +00:00
|
|
|
/// For FREEZE PARTITION and UNFREEZE
|
2018-06-13 13:49:27 +00:00
|
|
|
String with_name;
|
|
|
|
|
2019-07-23 13:34:17 +00:00
|
|
|
enum MoveDestinationType
|
2019-07-18 15:19:03 +00:00
|
|
|
{
|
|
|
|
DISK,
|
|
|
|
VOLUME,
|
2019-09-17 11:59:09 +00:00
|
|
|
TABLE,
|
2020-11-24 14:24:48 +00:00
|
|
|
SHARD,
|
2019-07-18 15:19:03 +00:00
|
|
|
};
|
|
|
|
|
2020-03-17 17:22:41 +00:00
|
|
|
std::optional<MoveDestinationType> move_destination_type;
|
|
|
|
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2019-07-23 13:34:17 +00:00
|
|
|
String move_destination_name;
|
2019-07-18 15:19:03 +00:00
|
|
|
|
2018-06-13 13:49:27 +00:00
|
|
|
static std::optional<PartitionCommand> parse(const ASTAlterCommand * command);
|
2020-07-28 15:10:36 +00:00
|
|
|
/// Convert type of the command to string (use not only type, but also
|
|
|
|
/// different flags)
|
|
|
|
std::string typeToString() const;
|
2018-06-13 13:49:27 +00:00
|
|
|
};
|
|
|
|
|
2020-03-17 13:49:50 +00:00
|
|
|
using PartitionCommands = std::vector<PartitionCommand>;
|
2018-06-13 13:49:27 +00:00
|
|
|
|
2023-08-23 12:07:02 +00:00
|
|
|
/// Result of executing of a single partition commands. Partition commands quite
|
2020-07-28 15:10:36 +00:00
|
|
|
/// different, so some fields will be empty for some commands. Currently used in
|
|
|
|
/// ATTACH and FREEZE commands.
|
|
|
|
struct PartitionCommandResultInfo
|
|
|
|
{
|
|
|
|
/// Command type, always filled
|
|
|
|
String command_type;
|
|
|
|
/// Partition id, always filled
|
|
|
|
String partition_id;
|
|
|
|
/// Part name, always filled
|
|
|
|
String part_name;
|
|
|
|
/// Part name in /detached directory, filled in ATTACH
|
2023-08-23 12:07:02 +00:00
|
|
|
String old_part_name = {};
|
2020-07-30 17:03:26 +00:00
|
|
|
/// Absolute path to backup directory, filled in FREEZE
|
2023-08-23 12:07:02 +00:00
|
|
|
String backup_path = {};
|
2020-07-30 17:03:26 +00:00
|
|
|
/// Absolute path part backup, filled in FREEZE
|
2023-08-23 12:07:02 +00:00
|
|
|
String part_backup_path = {};
|
2020-07-28 15:10:36 +00:00
|
|
|
/// Name of the backup (specified by user or increment value), filled in
|
|
|
|
/// FREEZE
|
2023-08-23 12:07:02 +00:00
|
|
|
String backup_name = {};
|
2020-07-28 15:10:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using PartitionCommandsResultInfo = std::vector<PartitionCommandResultInfo>;
|
|
|
|
|
2022-09-02 08:54:48 +00:00
|
|
|
/// Convert partition commands result to Source from single Chunk, which will be
|
2020-07-28 15:10:36 +00:00
|
|
|
/// used to print info to the user. Tries to create narrowest table for given
|
|
|
|
/// results. For example, if all commands were FREEZE commands, than
|
|
|
|
/// old_part_name column will be absent.
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe convertCommandsResultToSource(const PartitionCommandsResultInfo & commands_result);
|
2018-06-13 13:49:27 +00:00
|
|
|
|
|
|
|
}
|