aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MergeTree/AlterConversions.h
blob: 4410b9c56e258524b15dd4d943a294f1864f14bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include <Storages/MutationCommands.h>
#include <string>
#include <unordered_map>


namespace DB
{


/// Alter conversions which should be applied on-fly for part.
/// Built from of the most recent mutation commands for part.
/// Now only ALTER RENAME COLUMN is applied.
class AlterConversions : private boost::noncopyable
{
public:
    AlterConversions() = default;

    struct RenamePair
    {
        std::string rename_to;
        std::string rename_from;
    };

    void addMutationCommand(const MutationCommand & command);
    const std::vector<RenamePair> & getRenameMap() const { return rename_map; }

    /// Column was renamed (lookup by value in rename_map)
    bool columnHasNewName(const std::string & old_name) const;
    /// Get new name for column (lookup by value in rename_map)
    std::string getColumnNewName(const std::string & old_name) const;
    /// Is this name is new name of column (lookup by key in rename_map)
    bool isColumnRenamed(const std::string & new_name) const;
    /// Get column old name before rename (lookup by key in rename_map)
    std::string getColumnOldName(const std::string & new_name) const;

private:
    /// Rename map new_name -> old_name.
    std::vector<RenamePair> rename_map;
};

using AlterConversionsPtr = std::shared_ptr<const AlterConversions>;

}