aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/Access/ASTRowPolicyName.h
blob: 86171475a0a102f0f48c9240699c19af08b2dbf5 (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
#pragma once

#include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOnCluster.h>
#include <Access/Common/RowPolicyDefs.h>


namespace DB
{
/** Represents a row policy's name in one of the following forms:
  * short_name ON [db.]table_name [ON CLUSTER 'cluster_name']
  * short_name [ON CLUSTER 'cluster_name'] ON [db.]table_name
  */
class ASTRowPolicyName : public IAST, public ASTQueryWithOnCluster
{
public:
    RowPolicyName full_name;
    String toString() const { return full_name.toString(); }

    String getID(char) const override { return "RowPolicyName"; }
    ASTPtr clone() const override { return std::make_shared<ASTRowPolicyName>(*this); }
    void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
    ASTPtr getRewrittenASTWithoutOnCluster(const WithoutOnClusterASTRewriteParams &) const override { return removeOnCluster<ASTRowPolicyName>(clone()); }

    void replaceEmptyDatabase(const String & current_database);
};


/** Represents multiple names of row policies, comma-separated, in one of the following forms:
  * short_name1 ON [db1.]table_name1 [, short_name2 ON [db2.]table_name2 ...] [ON CLUSTER 'cluster_name']
  * short_name1 [, short_name2 ...] ON [db.]table_name [ON CLUSTER 'cluster_name']
  * short_name1 [, short_name2 ...] [ON CLUSTER 'cluster_name'] ON [db.]table_name
  * short_name ON [db1.]table_name1 [, [db2.]table_name2 ...] [ON CLUSTER 'cluster_name']
  * short_name [ON CLUSTER 'cluster_name'] ON [db1.]table_name1 [, [db2.]table_name2 ...]
  */
class ASTRowPolicyNames : public IAST, public ASTQueryWithOnCluster
{
public:
    std::vector<RowPolicyName> full_names;
    Strings toStrings() const;

    String getID(char) const override { return "RowPolicyNames"; }
    ASTPtr clone() const override { return std::make_shared<ASTRowPolicyNames>(*this); }
    void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
    ASTPtr getRewrittenASTWithoutOnCluster(const WithoutOnClusterASTRewriteParams &) const override { return removeOnCluster<ASTRowPolicyNames>(clone()); }

    void replaceEmptyDatabase(const String & current_database);

private:
    String tableOrAsterisk(const String & table_name) const;
};
}