2013-08-07 13:07:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Storages/AlterCommands.h>
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Interpreters/IInterpreter.h>
|
|
|
|
#include <Parsers/ASTAlterQuery.h>
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2014-07-11 08:12:03 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Allows you add or remove a column in the table.
|
|
|
|
* It also allows you to manipulate the partitions of the MergeTree family tables.
|
2013-08-07 13:07:42 +00:00
|
|
|
*/
|
2015-06-18 02:11:05 +00:00
|
|
|
class InterpreterAlterQuery : public IInterpreter
|
2013-08-07 13:07:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-23 18:01:50 +00:00
|
|
|
InterpreterAlterQuery(const ASTPtr & query_ptr_, const Context & context_);
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockIO execute() override;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
2014-07-11 08:12:03 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
struct PartitionCommand
|
|
|
|
{
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
DROP_PARTITION,
|
|
|
|
ATTACH_PARTITION,
|
|
|
|
FETCH_PARTITION,
|
|
|
|
FREEZE_PARTITION,
|
2017-06-22 11:01:30 +00:00
|
|
|
CLEAR_COLUMN,
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
ASTPtr partition;
|
2017-04-14 12:40:48 +00:00
|
|
|
Field column_name;
|
2017-06-02 21:37:28 +00:00
|
|
|
bool detach = false; /// true for DETACH PARTITION.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
bool part = false;
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
String from; /// For FETCH PARTITION - path in ZK to the shard, from which to download the partition.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// For FREEZE PARTITION
|
|
|
|
String with_name;
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
static PartitionCommand dropPartition(const ASTPtr & partition, bool detach)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = DROP_PARTITION;
|
|
|
|
res.partition = partition;
|
|
|
|
res.detach = detach;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
static PartitionCommand clearColumn(const ASTPtr & partition, const Field & column_name)
|
2017-04-14 12:40:48 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
2017-06-22 11:01:30 +00:00
|
|
|
res.type = CLEAR_COLUMN;
|
2017-04-14 12:40:48 +00:00
|
|
|
res.partition = partition;
|
|
|
|
res.column_name = column_name;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
static PartitionCommand attachPartition(const ASTPtr & partition, bool part)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = ATTACH_PARTITION;
|
|
|
|
res.partition = partition;
|
|
|
|
res.part = part;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
static PartitionCommand fetchPartition(const ASTPtr & partition, const String & from)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = FETCH_PARTITION;
|
|
|
|
res.partition = partition;
|
|
|
|
res.from = from;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
static PartitionCommand freezePartition(const ASTPtr & partition, const String & with_name)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
PartitionCommand res;
|
|
|
|
res.type = FREEZE_PARTITION;
|
|
|
|
res.partition = partition;
|
|
|
|
res.with_name = with_name;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-14 18:09:28 +00:00
|
|
|
class PartitionCommands : public std::vector<PartitionCommand>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void validate(const IStorage * table);
|
|
|
|
};
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
ASTPtr query_ptr;
|
|
|
|
|
2017-09-04 17:49:39 +00:00
|
|
|
const Context & context;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
static void parseAlter(const ASTAlterQuery::ParameterContainer & params,
|
|
|
|
AlterCommands & out_alter_commands, PartitionCommands & out_partition_commands);
|
2013-08-07 13:07:42 +00:00
|
|
|
};
|
2014-10-16 13:37:01 +00:00
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
}
|