2018-02-02 16:02:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-09-16 21:19:58 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/shared_ptr_helper.h>
|
2018-06-13 13:49:27 +00:00
|
|
|
#include <Parsers/ASTAlterQuery.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2020-01-13 16:39:20 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2019-12-18 13:09:58 +00:00
|
|
|
#include <Core/Names.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
|
2018-02-02 16:02:43 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-05-15 12:56:14 +00:00
|
|
|
class Context;
|
2018-07-11 12:43:55 +00:00
|
|
|
class WriteBuffer;
|
|
|
|
class ReadBuffer;
|
2018-05-15 12:56:14 +00:00
|
|
|
|
2019-12-12 16:24:03 +00:00
|
|
|
/// 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.
|
2018-02-02 16:02:43 +00:00
|
|
|
struct MutationCommand
|
|
|
|
{
|
2018-06-13 13:49:27 +00:00
|
|
|
ASTPtr ast; /// The AST of the whole command
|
|
|
|
|
2018-02-02 16:02:43 +00:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
EMPTY, /// Not used.
|
|
|
|
DELETE,
|
2018-08-07 13:58:11 +00:00
|
|
|
UPDATE,
|
2020-01-13 16:39:20 +00:00
|
|
|
MATERIALIZE_INDEX,
|
2021-02-10 14:12:49 +00:00
|
|
|
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,
|
2021-02-10 14:12:49 +00:00
|
|
|
DROP_PROJECTION,
|
2020-03-25 18:44:08 +00:00
|
|
|
MATERIALIZE_TTL,
|
|
|
|
RENAME_COLUMN,
|
2021-07-31 18:17:06 +00:00
|
|
|
MATERIALIZE_COLUMN,
|
2018-02-02 16:02:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type = EMPTY;
|
|
|
|
|
2019-12-12 16:24:03 +00:00
|
|
|
/// WHERE part of mutation
|
2018-02-02 16:02:43 +00:00
|
|
|
ASTPtr predicate;
|
|
|
|
|
2019-12-12 16:24:03 +00:00
|
|
|
/// Columns with corresponding actions
|
2018-08-07 13:58:11 +00:00
|
|
|
std::unordered_map<String, ASTPtr> column_to_update_expression;
|
|
|
|
|
2021-02-10 14:12:49 +00:00
|
|
|
/// For MATERIALIZE INDEX and PROJECTION
|
2019-05-05 17:01:54 +00:00
|
|
|
String index_name;
|
2021-02-10 14:12:49 +00:00
|
|
|
String projection_name;
|
2020-11-10 10:23:46 +00:00
|
|
|
|
|
|
|
/// 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);
|
2018-02-02 16:02:43 +00:00
|
|
|
};
|
|
|
|
|
2019-12-12 16:24:03 +00:00
|
|
|
/// Multiple mutation commands, possible from different ALTER queries
|
2021-09-16 21:19:58 +00:00
|
|
|
class MutationCommands : public shared_ptr_helper<MutationCommands>, public std::vector<MutationCommand>
|
2018-02-02 16:02:43 +00:00
|
|
|
{
|
2018-06-13 13:49:27 +00:00
|
|
|
public:
|
2020-12-04 02:15:44 +00:00
|
|
|
std::shared_ptr<ASTExpressionList> ast() const;
|
2018-04-19 10:33:16 +00:00
|
|
|
|
2018-07-11 12:43:55 +00:00
|
|
|
void writeText(WriteBuffer & out) const;
|
|
|
|
void readText(ReadBuffer & in);
|
2018-02-02 16:02:43 +00:00
|
|
|
};
|
|
|
|
|
2021-09-16 21:19:58 +00:00
|
|
|
using MutationCommandsConstPtr = std::shared_ptr<MutationCommands>;
|
|
|
|
|
2018-02-02 16:02:43 +00:00
|
|
|
}
|