ClickHouse/dbms/src/Parsers/ParserTablePropertiesQuery.cpp

95 lines
2.4 KiB
C++
Raw Normal View History

#include <Parsers/ASTIdentifier.h>
#include <Parsers/TablePropertiesQueriesASTs.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserTablePropertiesQuery.h>
#include <Common/typeid_cast.h>
2016-11-20 12:43:20 +00:00
namespace DB
{
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserKeyword s_exists("EXISTS");
ParserKeyword s_temporary("TEMPORARY");
ParserKeyword s_describe("DESCRIBE");
ParserKeyword s_desc("DESC");
ParserKeyword s_show("SHOW");
ParserKeyword s_create("CREATE");
ParserKeyword s_database("DATABASE");
ParserKeyword s_table("TABLE");
2019-10-08 12:34:04 +00:00
ParserKeyword s_dictionary("DICTIONARY");
ParserToken s_dot(TokenType::Dot);
ParserIdentifier name_p;
ASTPtr database;
ASTPtr table;
std::shared_ptr<ASTQueryWithTableAndOutput> query;
bool parse_only_database_name = false;
if (s_exists.ignore(pos, expected))
{
2019-10-08 13:26:15 +00:00
if (s_table.checkWithoutMoving(pos, expected))
2019-10-08 12:34:04 +00:00
query = std::make_shared<ASTExistsTableQuery>();
2019-10-08 13:26:15 +00:00
else if (s_dictionary.checkWithoutMoving(pos, expected))
2019-10-08 12:34:04 +00:00
query = std::make_shared<ASTExistsDictionaryQuery>();
}
else if (s_show.ignore(pos, expected))
{
if (!s_create.ignore(pos, expected))
return false;
if (s_database.ignore(pos, expected))
{
parse_only_database_name = true;
query = std::make_shared<ASTShowCreateDatabaseQuery>();
}
2019-10-08 13:26:15 +00:00
else if (s_table.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTShowCreateTableQuery>();
2019-10-08 12:34:04 +00:00
else
query = std::make_shared<ASTShowCreateDictionaryQuery>();
}
else
{
return false;
}
if (parse_only_database_name)
{
if (!name_p.parse(pos, database, expected))
return false;
}
else
{
if (s_temporary.ignore(pos, expected))
query->temporary = true;
2019-10-08 12:34:04 +00:00
if (!s_table.ignore(pos, expected) && !s_dictionary.ignore(pos, expected))
return false;
if (!name_p.parse(pos, table, expected))
return false;
if (s_dot.ignore(pos, expected))
{
database = table;
if (!name_p.parse(pos, table, expected))
return false;
}
}
2019-08-08 20:02:30 +00:00
tryGetIdentifierNameInto(database, query->database);
tryGetIdentifierNameInto(table, query->table);
node = query;
return true;
}
}