forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTCreateWorkloadQuery.cpp
More file actions
93 lines (73 loc) · 2.06 KB
/
ASTCreateWorkloadQuery.cpp
File metadata and controls
93 lines (73 loc) · 2.06 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
#include <Common/quoteString.h>
#include <Common/FieldVisitorToString.h>
#include <IO/Operators.h>
#include <Parsers/ASTCreateWorkloadQuery.h>
#include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTIdentifier.h>
namespace DB
{
ASTPtr ASTCreateWorkloadQuery::clone() const
{
auto res = std::make_shared<ASTCreateWorkloadQuery>(*this);
res->children.clear();
res->workload_name = workload_name->clone();
res->children.push_back(res->workload_name);
if (workload_parent)
{
res->workload_parent = workload_parent->clone();
res->children.push_back(res->workload_parent);
}
res->changes = changes;
return res;
}
void ASTCreateWorkloadQuery::formatImpl(WriteBuffer & ostr, const IAST::FormatSettings & format, IAST::FormatState &, IAST::FormatStateStacked) const
{
ostr << "CREATE ";
if (or_replace)
ostr << "OR REPLACE ";
ostr << "WORKLOAD ";
if (if_not_exists)
ostr << "IF NOT EXISTS ";
ostr << backQuoteIfNeed(getWorkloadName());
formatOnCluster(ostr, format);
if (hasParent())
{
ostr << " IN ";
ostr << backQuoteIfNeed(getWorkloadParent());
}
if (!changes.empty())
{
ostr << ' ' << "SETTINGS" << ' ';
bool first = true;
for (const auto & change : changes)
{
if (!first)
ostr << ", ";
else
first = false;
ostr << change.name << " = " << applyVisitor(FieldVisitorToString(), change.value);
if (!change.resource.empty())
{
ostr << ' ' << "FOR" << ' ';
ostr << backQuoteIfNeed(change.resource);
}
}
}
}
String ASTCreateWorkloadQuery::getWorkloadName() const
{
String name;
tryGetIdentifierNameInto(workload_name, name);
return name;
}
bool ASTCreateWorkloadQuery::hasParent() const
{
return workload_parent != nullptr;
}
String ASTCreateWorkloadQuery::getWorkloadParent() const
{
String name;
tryGetIdentifierNameInto(workload_parent, name);
return name;
}
}