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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#pragma once
#include <Parsers/ASTQueryWithTableAndOutput.h>
#include <Common/quoteString.h>
namespace DB
{
struct ASTExistsDatabaseQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsDatabaseQuery";
static constexpr auto Query = "EXISTS DATABASE";
/// No temporary databases are supported, just for parsing
static constexpr auto QueryTemporary = "";
};
struct ASTExistsTableQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsTableQuery";
static constexpr auto Query = "EXISTS TABLE";
static constexpr auto QueryTemporary = "EXISTS TEMPORARY TABLE";
};
struct ASTExistsViewQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsViewQuery";
static constexpr auto Query = "EXISTS VIEW";
/// No temporary view are supported, just for parsing
static constexpr auto QueryTemporary = "";
};
struct ASTExistsDictionaryQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsDictionaryQuery";
static constexpr auto Query = "EXISTS DICTIONARY";
/// No temporary dictionaries are supported, just for parsing
static constexpr auto QueryTemporary = "EXISTS TEMPORARY DICTIONARY";
};
struct ASTShowCreateTableQueryIDAndQueryNames
{
static constexpr auto ID = "ShowCreateTableQuery";
static constexpr auto Query = "SHOW CREATE TABLE";
static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY TABLE";
};
struct ASTShowCreateViewQueryIDAndQueryNames
{
static constexpr auto ID = "ShowCreateViewQuery";
static constexpr auto Query = "SHOW CREATE VIEW";
/// No temporary view are supported, just for parsing
static constexpr auto QueryTemporary = "";
};
struct ASTShowCreateDatabaseQueryIDAndQueryNames
{
static constexpr auto ID = "ShowCreateDatabaseQuery";
static constexpr auto Query = "SHOW CREATE DATABASE";
static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY DATABASE";
};
struct ASTShowCreateDictionaryQueryIDAndQueryNames
{
static constexpr auto ID = "ShowCreateDictionaryQuery";
static constexpr auto Query = "SHOW CREATE DICTIONARY";
/// No temporary dictionaries are supported, just for parsing
static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY DICTIONARY";
};
struct ASTDescribeQueryExistsQueryIDAndQueryNames
{
static constexpr auto ID = "DescribeQuery";
static constexpr auto Query = "DESCRIBE TABLE";
static constexpr auto QueryTemporary = "DESCRIBE TEMPORARY TABLE";
};
using ASTExistsTableQuery = ASTQueryWithTableAndOutputImpl<ASTExistsTableQueryIDAndQueryNames>;
using ASTExistsViewQuery = ASTQueryWithTableAndOutputImpl<ASTExistsViewQueryIDAndQueryNames>;
using ASTExistsDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDictionaryQueryIDAndQueryNames>;
using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateTableQueryIDAndQueryNames>;
using ASTShowCreateViewQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateViewQueryIDAndQueryNames>;
using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateDictionaryQueryIDAndQueryNames>;
class ASTExistsDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTExistsDatabaseQueryIDAndQueryNames>
{
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTExistsDatabaseQueryIDAndQueryNames::Query
<< " " << (settings.hilite ? hilite_none : "") << backQuoteIfNeed(getDatabase());
}
QueryKind getQueryKind() const override { return QueryKind::Exists; }
};
class ASTShowCreateDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTShowCreateDatabaseQueryIDAndQueryNames>
{
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTShowCreateDatabaseQueryIDAndQueryNames::Query
<< " " << (settings.hilite ? hilite_none : "") << backQuoteIfNeed(getDatabase());
}
};
class ASTDescribeQuery : public ASTQueryWithOutput
{
public:
ASTPtr table_expression;
String getID(char) const override { return "DescribeQuery"; }
ASTPtr clone() const override
{
auto res = std::make_shared<ASTDescribeQuery>(*this);
res->children.clear();
if (table_expression)
{
res->table_expression = table_expression->clone();
res->children.push_back(res->table_expression);
}
cloneOutputOptions(*res);
return res;
}
QueryKind getQueryKind() const override { return QueryKind::Describe; }
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "")
<< "DESCRIBE TABLE" << (settings.hilite ? hilite_none : "");
table_expression->formatImpl(settings, state, frame);
}
};
}
|