blob: af84399ae45e9d6158cce76809e1f7a1fd5d1ec7 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include <Parsers/Access/ASTUserNameWithHost.h>
#include <Common/quoteString.h>
#include <IO/Operators.h>
namespace DB
{
void ASTUserNameWithHost::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
{
settings.ostr << backQuoteIfNeed(base_name);
if (!host_pattern.empty())
settings.ostr << "@" << backQuoteIfNeed(host_pattern);
}
String ASTUserNameWithHost::toString() const
{
String res = base_name;
if (!host_pattern.empty())
res += '@' + host_pattern;
return res;
}
void ASTUserNameWithHost::concatParts()
{
base_name = toString();
host_pattern.clear();
}
void ASTUserNamesWithHost::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
{
assert(!names.empty());
bool need_comma = false;
for (const auto & name : names)
{
if (std::exchange(need_comma, true))
settings.ostr << ", ";
name->format(settings);
}
}
Strings ASTUserNamesWithHost::toStrings() const
{
Strings res;
res.reserve(names.size());
for (const auto & name : names)
res.emplace_back(name->toString());
return res;
}
void ASTUserNamesWithHost::concatParts()
{
for (auto & name : names)
name->concatParts();
}
bool ASTUserNamesWithHost::getHostPatternIfCommon(String & out_common_host_pattern) const
{
out_common_host_pattern.clear();
if (names.empty())
return true;
for (size_t i = 1; i != names.size(); ++i)
if (names[i]->host_pattern != names[0]->host_pattern)
return false;
out_common_host_pattern = names[0]->host_pattern;
return true;
}
}
|