2012-06-18 07:49:19 +00:00
|
|
|
#include <DB/Parsers/ASTLiteral.h>
|
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTShowTablesQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ParserShowTablesQuery.h>
|
|
|
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2014-06-12 00:48:56 +00:00
|
|
|
bool ParserShowTablesQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected & expected)
|
2012-06-18 07:49:19 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_show("SHOW", true, true);
|
|
|
|
ParserString s_tables("TABLES", true, true);
|
|
|
|
ParserString s_databases("DATABASES", true, true);
|
|
|
|
ParserString s_from("FROM", true, true);
|
2013-03-11 11:28:36 +00:00
|
|
|
ParserString s_not("NOT", true, true);
|
2012-07-27 19:20:44 +00:00
|
|
|
ParserString s_like("LIKE", true, true);
|
2013-02-20 13:14:12 +00:00
|
|
|
ParserString s_format("FORMAT", true, true);
|
2012-06-18 07:49:19 +00:00
|
|
|
ParserStringLiteral like_p;
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
ASTPtr like;
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr format;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
ASTShowTablesQuery * query = new ASTShowTablesQuery;
|
|
|
|
ASTPtr query_ptr = query;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!s_show.ignore(pos, end, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_databases.ignore(pos, end))
|
|
|
|
{
|
|
|
|
query->databases = true;
|
|
|
|
}
|
2013-02-21 11:12:31 +00:00
|
|
|
else if (s_tables.ignore(pos, end, expected))
|
2012-06-18 07:49:19 +00:00
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
if (s_from.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
if (!name_p.parse(pos, end, database, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
2013-03-11 11:28:36 +00:00
|
|
|
if (s_not.ignore(pos, end, expected))
|
2013-06-14 19:07:35 +00:00
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-03-11 11:28:36 +00:00
|
|
|
query->not_like = true;
|
2013-06-14 19:07:35 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
if (s_like.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
if (!like_p.parse(pos, end, like, expected))
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-11 11:28:36 +00:00
|
|
|
else if (query->not_like)
|
|
|
|
return false;
|
2013-02-21 10:39:24 +00:00
|
|
|
}
|
2013-02-21 11:12:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (s_format.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
ParserIdentifier format_p;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (!format_p.parse(pos, end, format, expected))
|
|
|
|
return false;
|
2014-06-26 00:58:14 +00:00
|
|
|
typeid_cast<ASTIdentifier &>(*format).kind = ASTIdentifier::Format;
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
query->range = StringRange(begin, pos);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
if (database)
|
2014-06-26 00:58:14 +00:00
|
|
|
query->from = typeid_cast<ASTIdentifier &>(*database).name;
|
2013-02-20 13:14:12 +00:00
|
|
|
if (like)
|
2014-06-26 00:58:14 +00:00
|
|
|
query->like = safeGet<const String &>(typeid_cast<ASTLiteral &>(*like).value);
|
2013-02-20 13:14:12 +00:00
|
|
|
if (format)
|
|
|
|
{
|
|
|
|
query->format = format;
|
|
|
|
query->children.push_back(format);
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-21 10:39:24 +00:00
|
|
|
node = query_ptr;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|