mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 03:12:43 +00:00
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <Core/NamesAndTypes.h>
|
|
#include <Storages/ColumnsDescription.h>
|
|
#include <optional>
|
|
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
class ASTAlterCommand;
|
|
|
|
/// Operation from the ALTER query (except for manipulation with PART/PARTITION). Adding Nested columns is not expanded to add individual columns.
|
|
struct AlterCommand
|
|
{
|
|
enum Type
|
|
{
|
|
ADD_COLUMN,
|
|
DROP_COLUMN,
|
|
MODIFY_COLUMN,
|
|
MODIFY_PRIMARY_KEY,
|
|
};
|
|
|
|
Type type;
|
|
|
|
String column_name;
|
|
|
|
/// For DROP COLUMN ... FROM PARTITION
|
|
String partition_name;
|
|
|
|
/// For ADD and MODIFY, a new column type.
|
|
DataTypePtr data_type;
|
|
|
|
ColumnDefaultKind default_kind{};
|
|
ASTPtr default_expression{};
|
|
|
|
/// For ADD - after which column to add a new one. If an empty string, add to the end. To add to the beginning now it is impossible.
|
|
String after_column;
|
|
|
|
/// For MODIFY_PRIMARY_KEY
|
|
ASTPtr primary_key;
|
|
|
|
AlterCommand() = default;
|
|
AlterCommand(const Type type, const String & column_name, const DataTypePtr & data_type,
|
|
const ColumnDefaultKind default_kind, const ASTPtr & default_expression,
|
|
const String & after_column = String{})
|
|
: type{type}, column_name{column_name}, data_type{data_type}, default_kind{default_kind},
|
|
default_expression{default_expression}, after_column{after_column}
|
|
{}
|
|
|
|
static std::optional<AlterCommand> parse(const ASTAlterCommand * command);
|
|
|
|
void apply(ColumnsDescription & columns_description) const;
|
|
|
|
};
|
|
|
|
class IStorage;
|
|
class Context;
|
|
|
|
class AlterCommands : public std::vector<AlterCommand>
|
|
{
|
|
public:
|
|
void apply(ColumnsDescription & columns_description) const;
|
|
|
|
void validate(const IStorage & table, const Context & context);
|
|
};
|
|
|
|
}
|