2012-08-02 19:03:32 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTLiteral.h>
|
|
|
|
#include <DB/Parsers/ASTSetQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ParserSetQuery.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// Парсит name = value.
|
2015-04-11 03:10:23 +00:00
|
|
|
static bool parseNameValuePair(ASTSetQuery::Change & change, IParser::Pos & pos, IParser::Pos end, IParser::Pos & max_parsed_pos, Expected & expected)
|
2012-08-02 19:03:32 +00:00
|
|
|
{
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
ParserLiteral value_p;
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_eq("=");
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-08-02 19:03:32 +00:00
|
|
|
ASTPtr name;
|
|
|
|
ASTPtr value;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, name, max_parsed_pos, expected))
|
2012-08-02 19:03:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!s_eq.ignore(pos, end, max_parsed_pos, expected))
|
2012-08-02 19:03:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!value_p.parse(pos, end, value, max_parsed_pos, expected))
|
2012-08-02 19:03:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
change.name = typeid_cast<const ASTIdentifier &>(*name).name;
|
|
|
|
change.value = typeid_cast<const ASTLiteral &>(*value).value;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
bool ParserSetQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
|
2012-08-02 19:03:32 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_comma(",");
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-06-05 21:28:04 +00:00
|
|
|
bool global = false;
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2015-06-05 21:28:04 +00:00
|
|
|
if (!parse_only_internals)
|
|
|
|
{
|
|
|
|
ParserString s_set("SET", true, true);
|
|
|
|
ParserString s_global("GLOBAL", true, true);
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2015-06-05 21:28:04 +00:00
|
|
|
ws.ignore(pos, end);
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2015-06-05 21:28:04 +00:00
|
|
|
if (!s_set.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
global = s_global.ignore(pos, end, max_parsed_pos, expected);
|
|
|
|
}
|
2012-08-02 19:03:32 +00:00
|
|
|
|
|
|
|
ASTSetQuery::Changes changes;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-08-02 19:03:32 +00:00
|
|
|
if (!changes.empty() && !s_comma.ignore(pos, end))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
changes.push_back(ASTSetQuery::Change());
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!parseNameValuePair(changes.back(), pos, end, max_parsed_pos, expected))
|
2012-08-02 19:03:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:42:22 +00:00
|
|
|
auto query = std::make_shared<ASTSetQuery>(StringRange(begin, pos));
|
2012-08-02 19:03:32 +00:00
|
|
|
node = query;
|
|
|
|
|
|
|
|
query->changes = changes;
|
|
|
|
query->global = global;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-08-02 19:03:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|