ClickHouse/dbms/src/Parsers/ParserSetQuery.cpp

77 lines
1.5 KiB
C++
Raw Normal View History

#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTSetQuery.h>
2012-08-02 19:03:32 +00:00
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserSetQuery.h>
2012-08-02 19:03:32 +00:00
#include <Common/typeid_cast.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`.
static bool parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected)
2012-08-02 19:03:32 +00:00
{
ParserIdentifier name_p;
ParserLiteral value_p;
ParserToken s_eq(TokenType::Equals);
ASTPtr name;
ASTPtr value;
2012-08-02 19:03:32 +00:00
if (!name_p.parse(pos, name, expected))
return false;
2012-08-02 19:03:32 +00:00
if (!s_eq.ignore(pos, expected))
return false;
2012-08-02 19:03:32 +00:00
if (!value_p.parse(pos, value, expected))
return false;
2012-08-02 19:03:32 +00:00
2019-08-08 20:02:30 +00:00
tryGetIdentifierNameInto(name, change.name);
change.value = value->as<ASTLiteral &>().value;
2012-08-02 19:03:32 +00:00
return true;
2012-08-02 19:03:32 +00:00
}
bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2012-08-02 19:03:32 +00:00
{
ParserToken s_comma(TokenType::Comma);
if (!parse_only_internals)
{
ParserKeyword s_set("SET");
2012-08-02 19:03:32 +00:00
if (!s_set.ignore(pos, expected))
return false;
}
2012-08-02 19:03:32 +00:00
SettingsChanges changes;
2012-08-02 19:03:32 +00:00
while (true)
{
if (!changes.empty() && !s_comma.ignore(pos))
break;
2012-08-02 19:03:32 +00:00
changes.push_back(SettingChange{});
2012-08-02 19:03:32 +00:00
if (!parseNameValuePair(changes.back(), pos, expected))
return false;
}
2012-08-02 19:03:32 +00:00
2018-02-26 03:37:08 +00:00
auto query = std::make_shared<ASTSetQuery>();
node = query;
2012-08-02 19:03:32 +00:00
query->is_standalone = !parse_only_internals;
query->changes = std::move(changes);
return true;
2012-08-02 19:03:32 +00:00
}
}