2013-08-07 13:07:42 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Storages/IStorage.h>
|
2014-07-11 08:12:03 +00:00
|
|
|
|
#include <DB/Storages/AlterCommands.h>
|
2013-08-07 13:07:42 +00:00
|
|
|
|
#include <DB/Interpreters/Context.h>
|
2015-06-18 02:11:05 +00:00
|
|
|
|
#include <DB/Interpreters/IInterpreter.h>
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
2014-07-11 08:12:03 +00:00
|
|
|
|
|
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2013-08-08 23:49:59 +00:00
|
|
|
|
/** Позволяет добавить или удалить столбец в таблице.
|
2014-10-09 20:28:33 +00:00
|
|
|
|
* Также позволяет осуществить манипуляции с партициями таблиц семейства MergeTree.
|
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:
|
2016-01-26 02:00:25 +00:00
|
|
|
|
InterpreterAlterQuery(ASTPtr query_ptr_, Context & context_);
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2015-06-18 02:11:05 +00:00
|
|
|
|
BlockIO execute() override;
|
2013-08-07 13:07:42 +00:00
|
|
|
|
|
2014-07-11 08:12:03 +00:00
|
|
|
|
/** Изменяет список столбцов в метаданных таблицы на диске. Нужно вызывать под TableStructureLock соответствующей таблицы.
|
|
|
|
|
*/
|
2014-10-16 13:37:01 +00:00
|
|
|
|
static void updateMetadata(const String & database,
|
|
|
|
|
const String & table,
|
|
|
|
|
const NamesAndTypesList & columns,
|
|
|
|
|
const NamesAndTypesList & materialized_columns,
|
|
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
|
const ColumnDefaults & column_defaults,
|
2016-01-26 02:00:25 +00:00
|
|
|
|
Context & context);
|
2014-07-11 08:12:03 +00:00
|
|
|
|
private:
|
2014-08-07 09:23:55 +00:00
|
|
|
|
struct PartitionCommand
|
|
|
|
|
{
|
|
|
|
|
enum Type
|
|
|
|
|
{
|
|
|
|
|
DROP_PARTITION,
|
2014-08-07 11:46:01 +00:00
|
|
|
|
ATTACH_PARTITION,
|
2014-10-09 20:28:33 +00:00
|
|
|
|
FETCH_PARTITION,
|
2014-11-11 04:11:07 +00:00
|
|
|
|
FREEZE_PARTITION,
|
2014-08-07 09:23:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
|
|
Field partition;
|
|
|
|
|
bool detach; /// true для DETACH PARTITION.
|
|
|
|
|
|
2014-08-07 11:46:01 +00:00
|
|
|
|
bool unreplicated;
|
|
|
|
|
bool part;
|
|
|
|
|
|
2014-10-09 20:28:33 +00:00
|
|
|
|
String from; /// Для FETCH PARTITION - путь в ZK к шарду, с которого скачивать партицию.
|
|
|
|
|
|
2015-04-21 13:10:08 +00:00
|
|
|
|
static PartitionCommand dropPartition(const Field & partition, bool detach, bool unreplicated)
|
2014-08-07 09:23:55 +00:00
|
|
|
|
{
|
2015-04-21 13:10:08 +00:00
|
|
|
|
return {DROP_PARTITION, partition, detach, unreplicated};
|
2014-08-07 09:23:55 +00:00
|
|
|
|
}
|
2014-08-07 11:46:01 +00:00
|
|
|
|
|
|
|
|
|
static PartitionCommand attachPartition(const Field & partition, bool unreplicated, bool part)
|
|
|
|
|
{
|
2014-08-08 08:28:13 +00:00
|
|
|
|
return {ATTACH_PARTITION, partition, false, unreplicated, part};
|
2014-08-07 11:46:01 +00:00
|
|
|
|
}
|
2014-10-09 20:28:33 +00:00
|
|
|
|
|
2014-10-15 19:59:12 +00:00
|
|
|
|
static PartitionCommand fetchPartition(const Field & partition, const String & from)
|
2014-10-09 20:28:33 +00:00
|
|
|
|
{
|
2014-10-15 19:59:12 +00:00
|
|
|
|
return {FETCH_PARTITION, partition, false, false, false, from};
|
2014-10-09 20:28:33 +00:00
|
|
|
|
}
|
2014-11-11 04:11:07 +00:00
|
|
|
|
|
|
|
|
|
static PartitionCommand freezePartition(const Field & partition)
|
|
|
|
|
{
|
|
|
|
|
return {FREEZE_PARTITION, partition};
|
|
|
|
|
}
|
2014-08-07 09:23:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::vector<PartitionCommand> PartitionCommands;
|
2014-08-06 10:26:35 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
ASTPtr query_ptr;
|
2014-10-07 09:09:59 +00:00
|
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
|
Context context;
|
2014-08-06 10:26:35 +00:00
|
|
|
|
|
2015-05-28 03:49:28 +00:00
|
|
|
|
static void parseAlter(const ASTAlterQuery::ParameterContainer & params,
|
2014-08-07 09:23:55 +00:00
|
|
|
|
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
|
|
|
|
}
|