forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTCreateResourceQuery.cpp
More file actions
98 lines (81 loc) · 2.21 KB
/
ASTCreateResourceQuery.cpp
File metadata and controls
98 lines (81 loc) · 2.21 KB
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
#include <Common/quoteString.h>
#include <IO/Operators.h>
#include <Parsers/ASTCreateResourceQuery.h>
#include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTIdentifier.h>
namespace DB
{
ASTPtr ASTCreateResourceQuery::clone() const
{
auto res = std::make_shared<ASTCreateResourceQuery>(*this);
res->children.clear();
res->resource_name = resource_name->clone();
res->children.push_back(res->resource_name);
res->operations = operations;
return res;
}
void ASTCreateResourceQuery::formatImpl(WriteBuffer & ostr, const IAST::FormatSettings & format, IAST::FormatState &, IAST::FormatStateStacked) const
{
ostr << "CREATE ";
if (or_replace)
ostr << "OR REPLACE ";
ostr << "RESOURCE ";
if (if_not_exists)
ostr << "IF NOT EXISTS ";
ostr << backQuoteIfNeed(getResourceName());
formatOnCluster(ostr, format);
ostr << " (";
bool first = true;
for (const auto & operation : operations)
{
if (!first)
ostr << ", ";
else
first = false;
if (operation.mode == ResourceAccessMode::MasterThread)
{
ostr << "MASTER THREAD";
}
else if (operation.mode == ResourceAccessMode::WorkerThread)
{
ostr << "WORKER THREAD";
}
else if (operation.mode == ResourceAccessMode::Query)
{
ostr << "QUERY";
}
else
{
switch (operation.mode)
{
case ResourceAccessMode::DiskRead:
{
ostr << "READ ";
break;
}
case ResourceAccessMode::DiskWrite:
{
ostr << "WRITE ";
break;
}
default:
chassert(false);
}
if (operation.disk)
{
ostr << "DISK ";
ostr << backQuoteIfNeed(*operation.disk);
}
else
ostr << "ANY DISK";
}
}
ostr << ")";
}
String ASTCreateResourceQuery::getResourceName() const
{
String name;
tryGetIdentifierNameInto(resource_name, name);
return name;
}
}