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
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, String & expected)
|
2012-12-15 03:09:04 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
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);
|
2013-02-20 13:14:12 +00:00
|
|
|
ParserString s_format("FORMAT", true, true);
|
2012-12-15 03:09:04 +00:00
|
|
|
ParserString s_dot(".");
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
2013-02-20 13:14:12 +00:00
|
|
|
ASTPtr format;
|
2013-02-21 10:02:33 +00:00
|
|
|
ASTPtr query_ptr;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2013-10-21 11:06:26 +00:00
|
|
|
bool describe_query = false;
|
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
ws.ignore(pos, end);
|
2013-02-21 11:34:32 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
if (s_exists.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
query_ptr = new ASTExistsQuery;
|
|
|
|
}
|
|
|
|
else if (s_describe.ignore(pos, end, expected) || s_desc.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
query_ptr = new ASTDescribeQuery;
|
2013-10-21 11:06:26 +00:00
|
|
|
describe_query = true;
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|
2013-02-21 11:12:31 +00:00
|
|
|
else if (s_show.ignore(pos, end, expected))
|
2013-02-21 10:02:33 +00:00
|
|
|
{
|
2013-02-21 11:34:32 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2013-02-21 11:12:31 +00:00
|
|
|
if (!s_create.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2013-02-21 11:34:32 +00:00
|
|
|
|
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!s_table.ignore(pos, end, expected))
|
2013-10-21 11:06:26 +00:00
|
|
|
/// для запроса DESC/DESCRIBE слово table опционально, чтобы было больше похоже на mysql
|
|
|
|
if (!describe_query)
|
|
|
|
return false;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!name_p.parse(pos, end, table, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_dot.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
database = table;
|
|
|
|
if (!name_p.parse(pos, end, table, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
2013-02-20 13:14:12 +00:00
|
|
|
|
|
|
|
if (s_format.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
ParserIdentifier format_p;
|
|
|
|
|
|
|
|
if (!format_p.parse(pos, end, format, expected))
|
|
|
|
return false;
|
|
|
|
dynamic_cast<ASTIdentifier &>(*format).kind = ASTIdentifier::Format;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
ASTQueryWithTableAndOutput * query = dynamic_cast<ASTQueryWithTableAndOutput *>(&*query_ptr);
|
2012-12-15 03:09:04 +00:00
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
query->range = StringRange(begin, pos);
|
|
|
|
|
2012-12-15 03:09:04 +00:00
|
|
|
if (database)
|
|
|
|
query->database = dynamic_cast<ASTIdentifier &>(*database).name;
|
|
|
|
if (table)
|
|
|
|
query->table = dynamic_cast<ASTIdentifier &>(*table).name;
|
2013-02-20 13:14:12 +00:00
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
query->format = format;
|
|
|
|
query->children.push_back(format);
|
|
|
|
}
|
2013-02-21 10:02:33 +00:00
|
|
|
|
|
|
|
node = query_ptr;
|
2012-12-15 03:09:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|