ClickHouse/src/Storages/MutationCommands.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
#include <optional>
#include <vector>
#include <memory>
#include <unordered_map>
#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>
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,
2022-12-22 13:31:42 +00:00
ALTER_WITHOUT_MUTATION, /// pure metadata command, currently unusned
};
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);
/// This command shouldn't stick with other commands
bool isBarrierCommand() const;
};
/// Multiple mutation commands, possible from different ALTER queries
class MutationCommands : public std::vector<MutationCommand>
{
public:
2022-12-22 13:31:42 +00:00
std::shared_ptr<ASTExpressionList> ast(bool with_pure_metadata_commands = false) const;
2022-12-22 13:31:42 +00:00
void writeText(WriteBuffer & out, bool with_pure_metadata_commands) const;
void readText(ReadBuffer & in);
2022-12-22 13:31:42 +00:00
std::string toString() const;
bool hasNonEmptyMutationCommands() const;
/// These set of commands contain barrier command and shouldn't
/// stick with other commands. Commands from one set have already been validated
/// to be executed without issues on the creation state.
bool containBarrierCommand() const;
};
using MutationCommandsConstPtr = std::shared_ptr<MutationCommands>;
}