mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <DB/Storages/IStorage.h>
|
|
#include <DB/Storages/AlterCommands.h>
|
|
#include <DB/Interpreters/Context.h>
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
|
|
|
|
/** Позволяет добавить или удалить столбец в таблице.
|
|
*/
|
|
class InterpreterAlterQuery
|
|
{
|
|
public:
|
|
InterpreterAlterQuery(ASTPtr query_ptr_, Context & context_);
|
|
|
|
void execute();
|
|
|
|
/** Изменяет список столбцов в метаданных таблицы на диске. Нужно вызывать под TableStructureLock соответствующей таблицы.
|
|
*/
|
|
static void updateMetadata(const String & database, const String & table, const NamesAndTypesList & columns, Context & context);
|
|
private:
|
|
struct PartitionCommand
|
|
{
|
|
enum Type
|
|
{
|
|
DROP_PARTITION,
|
|
ATTACH_PARTITION,
|
|
};
|
|
|
|
Type type;
|
|
|
|
Field partition;
|
|
bool detach; /// true для DETACH PARTITION.
|
|
|
|
bool unreplicated;
|
|
bool part;
|
|
|
|
static PartitionCommand dropPartition(const Field & partition, bool detach)
|
|
{
|
|
return {DROP_PARTITION, partition, detach};
|
|
}
|
|
|
|
static PartitionCommand attachPartition(const Field & partition, bool unreplicated, bool part)
|
|
{
|
|
return {ATTACH_PARTITION, partition, false, unreplicated, part};
|
|
}
|
|
};
|
|
|
|
typedef std::vector<PartitionCommand> PartitionCommands;
|
|
|
|
ASTPtr query_ptr;
|
|
|
|
Context context;
|
|
|
|
static void parseAlter(const ASTAlterQuery::ParameterContainer & params, const DataTypeFactory & data_type_factory,
|
|
AlterCommands & out_alter_commands, PartitionCommands & out_partition_commands);
|
|
};
|
|
}
|