ClickHouse/dbms/Storages/MutationCommands.h

71 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/ASTAlterQuery.h>
#include <Storages/IStorage_fwd.h>
2020-01-13 16:39:20 +00:00
#include <DataTypes/IDataType.h>
#include <Core/Names.h>
#include <optional>
#include <unordered_map>
namespace DB
{
class Context;
class WriteBuffer;
class ReadBuffer;
/// Represents set of actions which should be applied
/// to values from set of columns which statisfy predicate.
struct MutationCommand
{
ASTPtr ast; /// The AST of the whole command
enum Type
{
EMPTY, /// Not used.
DELETE,
UPDATE,
2020-01-13 16:39:20 +00:00
MATERIALIZE_INDEX,
2020-01-17 13:54:22 +00:00
READ_COLUMN,
DROP_COLUMN,
DROP_INDEX,
2020-01-22 13:24:20 +00:00
MATERIALIZE_TTL
};
Type type = EMPTY;
/// WHERE part of mutation
ASTPtr predicate;
/// Columns with corresponding actions
std::unordered_map<String, ASTPtr> column_to_update_expression;
2019-04-10 17:44:39 +00:00
/// For MATERIALIZE INDEX
2019-05-05 17:01:54 +00:00
String index_name;
2019-04-10 17:44:39 +00:00
ASTPtr partition;
2020-01-17 13:54:22 +00:00
/// For reads, drops and etc.
2020-01-13 16:39:20 +00:00
String column_name;
2020-01-28 17:15:22 +00:00
DataTypePtr data_type; /// Maybe empty if we just want to drop column
2020-01-13 16:39:20 +00:00
2020-03-17 13:49:50 +00:00
/// We need just clear column, not drop from metadata.
bool clear = false;
/// If parse_alter_commands, than consider more Alter commands as mutation commands
2020-03-22 00:50:06 +00:00
static std::optional<MutationCommand> parse(ASTAlterCommand * command, bool parse_alter_commands = false);
};
/// Multiple mutation commands, possible from different ALTER queries
class MutationCommands : public std::vector<MutationCommand>
{
public:
std::shared_ptr<ASTAlterCommandList> ast() const;
void writeText(WriteBuffer & out) const;
void readText(ReadBuffer & in);
};
}