2021-11-26 15:49:40 +00:00
|
|
|
#include <Parsers/ASTIdentifier_fwd.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Parsers/ASTSetQuery.h>
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2020-12-10 22:05:02 +00:00
|
|
|
#include <Common/SettingsChanges.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2012-08-02 19:03:32 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-04-02 17:37:49 +00:00
|
|
|
/// Parse `name = value`.
|
2020-04-24 16:04:54 +00:00
|
|
|
bool ParserSetQuery::parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected)
|
2012-08-02 19:03:32 +00:00
|
|
|
{
|
2020-08-08 18:55:14 +00:00
|
|
|
ParserCompoundIdentifier name_p;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserLiteral value_p;
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_eq(TokenType::Equals);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr name;
|
|
|
|
ASTPtr value;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!name_p.parse(pos, name, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_eq.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2020-06-12 04:21:43 +00:00
|
|
|
if (ParserKeyword("TRUE").ignore(pos, expected))
|
|
|
|
value = std::make_shared<ASTLiteral>(Field(UInt64(1)));
|
|
|
|
else if (ParserKeyword("FALSE").ignore(pos, expected))
|
|
|
|
value = std::make_shared<ASTLiteral>(Field(UInt64(0)));
|
|
|
|
else if (!value_p.parse(pos, value, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2019-08-08 20:02:30 +00:00
|
|
|
tryGetIdentifierNameInto(name, change.name);
|
2019-03-15 16:14:13 +00:00
|
|
|
change.value = value->as<ASTLiteral &>().value;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-08-02 19:03:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2012-08-02 19:03:32 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
ParserToken s_comma(TokenType::Comma);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!parse_only_internals)
|
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_set("SET");
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_set.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2019-04-18 23:29:32 +00:00
|
|
|
SettingsChanges changes;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!changes.empty() && !s_comma.ignore(pos))
|
2017-04-01 07:20:54 +00:00
|
|
|
break;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2019-04-18 23:29:32 +00:00
|
|
|
changes.push_back(SettingChange{});
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!parseNameValuePair(changes.back(), pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
auto query = std::make_shared<ASTSetQuery>();
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
query->is_standalone = !parse_only_internals;
|
2019-04-18 23:29:32 +00:00
|
|
|
query->changes = std::move(changes);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-08-02 19:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|