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>
|
2014-07-11 08:12:03 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.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
|
|
|
/** Позволяет добавить или удалить столбец в таблице.
|
2013-08-07 13:07:42 +00:00
|
|
|
*/
|
|
|
|
class InterpreterAlterQuery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InterpreterAlterQuery(ASTPtr query_ptr_, Context & context_);
|
|
|
|
|
|
|
|
void execute();
|
|
|
|
|
2014-07-11 08:12:03 +00:00
|
|
|
/** Изменяет список столбцов в метаданных таблицы на диске. Нужно вызывать под TableStructureLock соответствующей таблицы.
|
|
|
|
*/
|
|
|
|
static void updateMetadata(const String & database, const String & table, const NamesAndTypesList & columns, Context & context);
|
|
|
|
private:
|
2014-08-07 09:23:55 +00:00
|
|
|
struct PartitionCommand
|
|
|
|
{
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
DROP_PARTITION,
|
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
Field partition;
|
|
|
|
bool detach; /// true для DETACH PARTITION.
|
|
|
|
|
|
|
|
static PartitionCommand dropPartition(const Field & partition, bool detach)
|
|
|
|
{
|
|
|
|
return {DROP_PARTITION, partition, detach};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<PartitionCommand> PartitionCommands;
|
2014-08-06 10:26:35 +00:00
|
|
|
|
2013-08-07 13:07:42 +00:00
|
|
|
ASTPtr query_ptr;
|
|
|
|
|
|
|
|
Context context;
|
2014-08-06 10:26:35 +00:00
|
|
|
|
|
|
|
static void parseAlter(const ASTAlterQuery::ParameterContainer & params, const DataTypeFactory & data_type_factory,
|
2014-08-07 09:23:55 +00:00
|
|
|
AlterCommands & out_alter_commands, PartitionCommands & out_partition_commands);
|
2013-08-07 13:07:42 +00:00
|
|
|
};
|
|
|
|
}
|