2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/TablePropertiesQueriesASTs.h>
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ParserTablePropertiesQuery.h>
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
|
2012-12-15 03:09:04 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Pos begin = pos;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-06-15 17:55:57 +00:00
|
|
|
ParserWhitespaceOrComments ws;
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserString s_exists("EXISTS", true, true);
|
|
|
|
ParserString s_describe("DESCRIBE", true, true);
|
|
|
|
ParserString s_desc("DESC", true, true);
|
|
|
|
ParserString s_show("SHOW", true, true);
|
|
|
|
ParserString s_create("CREATE", true, true);
|
|
|
|
ParserString s_table("TABLE", true, true);
|
|
|
|
ParserString s_dot(".");
|
|
|
|
ParserIdentifier name_p;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
|
|
|
std::shared_ptr<ASTQueryWithTableAndOutput> query;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (s_exists.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
{
|
|
|
|
query = std::make_shared<ASTExistsQuery>();
|
|
|
|
}
|
|
|
|
else if (s_describe.ignore(pos, end, max_parsed_pos, expected) || s_desc.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
{
|
|
|
|
query = std::make_shared<ASTDescribeQuery>();
|
|
|
|
}
|
|
|
|
else if (s_show.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!s_create.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
query = std::make_shared<ASTShowCreateQuery>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
s_table.ignore(pos, end, max_parsed_pos, expected);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
|
|
|
return false;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (s_dot.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
{
|
|
|
|
database = table;
|
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
|
|
|
return false;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
query->range = StringRange(begin, pos);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (database)
|
|
|
|
query->database = typeid_cast<ASTIdentifier &>(*database).name;
|
|
|
|
if (table)
|
|
|
|
query->table = typeid_cast<ASTIdentifier &>(*table).name;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-12-15 03:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|