2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/ASTShowTablesQuery.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ParserShowTablesQuery.h>
|
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2012-06-18 07:49:19 +00:00
|
|
|
{
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_show("SHOW");
|
2018-01-25 17:50:57 +00:00
|
|
|
ParserKeyword s_temporary("TEMPORARY");
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword s_tables("TABLES");
|
|
|
|
ParserKeyword s_databases("DATABASES");
|
|
|
|
ParserKeyword s_from("FROM");
|
|
|
|
ParserKeyword s_not("NOT");
|
|
|
|
ParserKeyword s_like("LIKE");
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserStringLiteral like_p;
|
|
|
|
ParserIdentifier name_p;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr like;
|
|
|
|
ASTPtr database;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
auto query = std::make_shared<ASTShowTablesQuery>();
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (!s_show.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (s_databases.ignore(pos))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
query->databases = true;
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s_temporary.ignore(pos))
|
2018-01-25 17:50:57 +00:00
|
|
|
query->temporary = true;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2018-01-25 17:50:57 +00:00
|
|
|
if (s_tables.ignore(pos, expected))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-02-02 13:17:45 +00:00
|
|
|
if (s_from.ignore(pos, expected))
|
|
|
|
{
|
2018-01-25 17:50:57 +00:00
|
|
|
if (!name_p.parse(pos, database, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_not.ignore(pos, expected))
|
|
|
|
query->not_like = true;
|
|
|
|
|
2018-02-02 13:17:45 +00:00
|
|
|
if (s_like.ignore(pos, expected))
|
|
|
|
{
|
2018-01-25 17:50:57 +00:00
|
|
|
if (!like_p.parse(pos, like, expected))
|
|
|
|
return false;
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
|
|
|
else if (query->not_like)
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
|
|
|
else
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
getIdentifierName(database, query->from);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (like)
|
2019-03-11 13:22:51 +00:00
|
|
|
query->like = safeGet<const String &>(like->as<ASTLiteral>()->value);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
node = query;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2012-06-18 07:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|