2012-12-15 03:09:04 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
2013-02-21 10:02:33 +00:00
|
|
|
#include <DB/Parsers/TablePropertiesQueriesASTs.h>
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
2013-02-21 10:02:33 +00:00
|
|
|
#include <DB/Parsers/ParserTablePropertiesQuery.h>
|
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
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserString s_exists("EXISTS", true, true);
|
2013-02-21 10:02:33 +00:00
|
|
|
ParserString s_describe("DESCRIBE", true, true);
|
|
|
|
ParserString s_desc("DESC", true, true);
|
2013-02-21 11:12:31 +00:00
|
|
|
ParserString s_show("SHOW", true, true);
|
|
|
|
ParserString s_create("CREATE", true, true);
|
2012-12-15 03:09:04 +00:00
|
|
|
ParserString s_table("TABLE", true, true);
|
|
|
|
ParserString s_dot(".");
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
2013-02-21 10:02:33 +00:00
|
|
|
ASTPtr query_ptr;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (s_exists.ignore(pos, end, max_parsed_pos, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
|
|
|
query_ptr = new ASTExistsQuery;
|
|
|
|
}
|
2015-04-11 03:10:23 +00:00
|
|
|
else if (s_describe.ignore(pos, end, max_parsed_pos, expected) || s_desc.ignore(pos, end, max_parsed_pos, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
|
|
|
query_ptr = new ASTDescribeQuery;
|
|
|
|
}
|
2015-04-11 03:10:23 +00:00
|
|
|
else if (s_show.ignore(pos, end, max_parsed_pos, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
2013-02-21 11:34:32 +00:00
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!s_create.ignore(pos, end, max_parsed_pos, expected))
|
2013-02-21 11:12:31 +00:00
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
query_ptr = new ASTShowCreateQuery;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 03:09:04 +00:00
|
|
|
return false;
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-10-21 14:57:10 +00:00
|
|
|
ASTQueryWithTableAndOutput * query = dynamic_cast<ASTQueryWithTableAndOutput *>(&*query_ptr);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
s_table.ignore(pos, end, max_parsed_pos, expected);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
2012-12-15 03:09:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2015-04-11 03:10:23 +00:00
|
|
|
if (s_dot.ignore(pos, end, max_parsed_pos, expected))
|
2012-12-15 03:09:04 +00:00
|
|
|
{
|
|
|
|
database = table;
|
2015-04-11 03:10:23 +00:00
|
|
|
if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
|
2012-12-15 03:09:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-10-21 14:57:10 +00:00
|
|
|
/// FORMAT format_name
|
|
|
|
if (!parseFormat(*query, pos, end, node, max_parsed_pos, expected))
|
|
|
|
return false;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
query->range = StringRange(begin, pos);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
if (database)
|
2014-06-26 00:58:14 +00:00
|
|
|
query->database = typeid_cast<ASTIdentifier &>(*database).name;
|
2012-12-15 03:09:04 +00:00
|
|
|
if (table)
|
2014-06-26 00:58:14 +00:00
|
|
|
query->table = typeid_cast<ASTIdentifier &>(*table).name;
|
2015-10-21 14:57:10 +00:00
|
|
|
if (query->format)
|
|
|
|
query->children.push_back(query->format);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
node = query_ptr;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|