ClickHouse/dbms/src/Parsers/ParserShowTablesQuery.cpp

88 lines
2.1 KiB
C++
Raw Normal View History

#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTShowTablesQuery.h>
2012-06-18 07:49:19 +00:00
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserShowTablesQuery.h>
#include <Parsers/ExpressionElementParsers.h>
2019-09-15 16:07:27 +00:00
#include <Parsers/ExpressionListParsers.h>
2012-06-18 07:49:19 +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
{
bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2012-06-18 07:49:19 +00:00
{
ParserKeyword s_show("SHOW");
ParserKeyword s_temporary("TEMPORARY");
ParserKeyword s_tables("TABLES");
ParserKeyword s_databases("DATABASES");
ParserKeyword s_from("FROM");
ParserKeyword s_not("NOT");
ParserKeyword s_like("LIKE");
2019-09-15 16:07:27 +00:00
ParserKeyword s_limit("LIMIT");
ParserStringLiteral like_p;
ParserIdentifier name_p;
2019-09-15 16:07:27 +00:00
ParserExpressionWithOptionalAlias limit_p(false);
2012-06-18 07:49:19 +00:00
ASTPtr like;
ASTPtr database;
auto query = std::make_shared<ASTShowTablesQuery>();
2012-06-18 07:49:19 +00:00
if (!s_show.ignore(pos, expected))
return false;
2012-06-18 07:49:19 +00:00
if (s_databases.ignore(pos))
{
query->databases = true;
2018-02-02 13:17:45 +00:00
}
else
{
if (s_temporary.ignore(pos))
query->temporary = true;
2012-06-18 07:49:19 +00:00
if (s_tables.ignore(pos, expected))
{
2018-02-02 13:17:45 +00:00
if (s_from.ignore(pos, expected))
{
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))
{
if (!like_p.parse(pos, like, expected))
return false;
2018-02-02 13:17:45 +00:00
}
else if (query->not_like)
return false;
2019-09-15 16:07:27 +00:00
if (s_limit.ignore(pos, expected))
{
if (!limit_p.parse(pos, query->limit_length, expected))
return false;
}
2018-02-02 13:17:45 +00:00
}
else
return false;
}
2019-08-08 20:02:30 +00:00
tryGetIdentifierNameInto(database, query->from);
if (like)
query->like = safeGet<const String &>(like->as<ASTLiteral &>().value);
node = query;
2012-06-18 07:49:19 +00:00
return true;
2012-06-18 07:49:19 +00:00
}
}