ClickHouse/dbms/src/Storages/MutationCommands.h

63 lines
1.2 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 <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-15 13:00:08 +00:00
READ
};
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-13 16:39:20 +00:00
/// For cast
String column_name;
DataTypePtr data_type;
2020-01-15 13:00:08 +00:00
static std::optional<MutationCommand> parse(ASTAlterCommand * command, bool parse_modify=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);
};
}