aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ASTTableOverrides.h
blob: 1df267acaa946e1c22a7d33d3b24a235eae1f07f (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
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <Parsers/IAST.h>

#include <map>


namespace DB
{

class ASTColumns;
class ASTCreateQuery;
class ASTIdentifier;
class ASTStorage;

/// Storage and column overrides for a single table, for example:
///
///   TABLE OVERRIDE `foo` (PARTITION BY toYYYYMM(`createtime`))
///
class ASTTableOverride : public IAST
{
public:
    String table_name;
    ASTColumns * columns = nullptr;
    ASTStorage * storage = nullptr;
    bool is_standalone = true;
    String getID(char) const override { return "TableOverride " + table_name; }
    ASTPtr clone() const override;
    void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;

    void forEachPointerToChild(std::function<void(void**)> f) override
    {
        f(reinterpret_cast<void **>(&columns));
        f(reinterpret_cast<void **>(&storage));
    }
};

/// List of table overrides, for example:
///
///   TABLE OVERRIDE `foo` (PARTITION BY toYYYYMM(`createtime`)),
///   TABLE OVERRIDE `bar` (SAMPLE BY `id`)
///
class ASTTableOverrideList : public IAST
{
public:
    String getID(char) const override { return "TableOverrideList"; }
    ASTPtr clone() const override;
    void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
    void setTableOverride(const String & name, ASTPtr ast);
    void removeTableOverride(const String & name);
    ASTPtr tryGetTableOverride(const String & name) const;
    bool hasOverride(const String & name) const;

private:
    std::map<String, size_t> positions;
};

}