ClickHouse/src/Storages/MutationCommands.h

81 lines
1.9 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
2020-08-08 00:47:03 +00:00
/// to values from set of columns which satisfy 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,
MATERIALIZE_PROJECTION,
2020-07-21 14:05:30 +00:00
READ_COLUMN, /// Read column and apply conversions (MODIFY COLUMN alter query).
2020-01-17 13:54:22 +00:00
DROP_COLUMN,
DROP_INDEX,
DROP_PROJECTION,
2020-03-25 18:44:08 +00:00
MATERIALIZE_TTL,
RENAME_COLUMN,
2021-07-31 18:17:06 +00:00
MATERIALIZE_COLUMN,
};
Type type = EMPTY;
/// WHERE part of mutation
ASTPtr predicate;
/// Columns with corresponding actions
std::unordered_map<String, ASTPtr> column_to_update_expression;
/// For MATERIALIZE INDEX and PROJECTION
2019-05-05 17:01:54 +00:00
String index_name;
String projection_name;
/// For MATERIALIZE INDEX, UPDATE and DELETE.
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;
2020-03-25 18:44:08 +00:00
/// Column rename_to
String rename_to;
2020-03-17 13:49:50 +00:00
/// 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<ASTExpressionList> ast() const;
void writeText(WriteBuffer & out) const;
void readText(ReadBuffer & in);
};
}