Repository navigation
Expand file tree
/
Copy pathSettingFieldASTFunction.cpp
More file actions
87 lines (69 loc) · 1.92 KB
/
Copy pathSettingFieldASTFunction.cpp
File metadata and controls
87 lines (69 loc) · 1.92 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
#include <Core/SettingFieldASTFunction.h>
#include <Core/Defines.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/parseQuery.h>
#include <Common/Exception.h>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
namespace
{
boost::intrusive_ptr<ASTFunction> parseASTFunction(const String & str)
{
if (str.empty())
return nullptr;
ParserFunction parser;
ASTPtr ast = parseQuery(parser, str, /*max_query_size=*/0, /*max_parser_depth=*/DBMS_DEFAULT_MAX_PARSER_DEPTH, /*max_parser_backtracks=*/DBMS_DEFAULT_MAX_PARSER_BACKTRACKS);
auto * func = typeid_cast<ASTFunction *>(ast.get());
if (!func)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Expected a function, got: {}", str);
return boost::intrusive_ptr<ASTFunction>(func);
}
}
SettingFieldASTFunction::SettingFieldASTFunction(const boost::intrusive_ptr<ASTFunction> & func)
: value{func}
{
}
SettingFieldASTFunction::SettingFieldASTFunction(const String & str)
: value{parseASTFunction(str)}
{
}
SettingFieldASTFunction::SettingFieldASTFunction(const Field & f)
: SettingFieldASTFunction{f.safeGet<String>()}
{
}
SettingFieldASTFunction & SettingFieldASTFunction::operator =(const String & str)
{
value = parseASTFunction(str);
changed = true;
return *this;
}
SettingFieldASTFunction & SettingFieldASTFunction::operator =(const Field & f)
{
*this = f.safeGet<String>();
return *this;
}
String SettingFieldASTFunction::toString() const
{
return value ? value->formatWithSecretsOneLine() : String{};
}
void SettingFieldASTFunction::parseFromString(const String & str)
{
*this = str;
}
void SettingFieldASTFunction::writeBinary(WriteBuffer & out) const
{
writeStringBinary(toString(), out);
}
void SettingFieldASTFunction::readBinary(ReadBuffer & in)
{
String str;
readStringBinary(str, in);
*this = str;
}
}