未验证 提交 849ca482 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #18458 from spongedu/support_exists_database

support EXISTS DATABASE syntax
......@@ -53,6 +53,12 @@ BlockInputStreamPtr InterpreterExistsQuery::executeImpl()
result = DatabaseCatalog::instance().isTableExist({database, exists_query->table}, context);
}
}
else if ((exists_query = query_ptr->as<ASTExistsDatabaseQuery>()))
{
String database = context.resolveDatabase(exists_query->database);
context.checkAccess(AccessType::SHOW_DATABASES, database);
result = DatabaseCatalog::instance().isDatabaseExist(database);
}
else if ((exists_query = query_ptr->as<ASTExistsDictionaryQuery>()))
{
if (exists_query->temporary)
......
......@@ -148,6 +148,10 @@ std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, Context &
{
return std::make_unique<InterpreterOptimizeQuery>(query, context);
}
else if (query->as<ASTExistsDatabaseQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
else if (query->as<ASTExistsTableQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
......
......@@ -34,15 +34,23 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
bool temporary = false;
if (s_exists.ignore(pos, expected))
{
if (s_temporary.ignore(pos, expected))
temporary = true;
if (s_table.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTExistsTableQuery>();
else if (s_dictionary.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTExistsDictionaryQuery>();
if (s_database.ignore(pos, expected))
{
query = std::make_shared<ASTExistsDatabaseQuery>();
parse_only_database_name = true;
}
else
query = std::make_shared<ASTExistsTableQuery>();
{
if (s_temporary.ignore(pos, expected))
temporary = true;
if (s_table.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTExistsTableQuery>();
else if (s_dictionary.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTExistsDictionaryQuery>();
else
query = std::make_shared<ASTExistsTableQuery>();
}
}
else if (s_show.ignore(pos, expected))
{
......
......@@ -7,6 +7,14 @@
namespace DB
{
struct ASTExistsDatabaseQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsDatabaseQuery";
static constexpr auto Query = "EXISTS DATABASE";
/// No temporary databases are supported, just for parsing
static constexpr auto QueryTemporary = "";
};
struct ASTExistsTableQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsTableQuery";
......@@ -51,6 +59,7 @@ struct ASTDescribeQueryExistsQueryIDAndQueryNames
static constexpr auto QueryTemporary = "DESCRIBE TEMPORARY TABLE";
};
using ASTExistsDatabaseQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDatabaseQueryIDAndQueryNames>;
using ASTExistsTableQuery = ASTQueryWithTableAndOutputImpl<ASTExistsTableQueryIDAndQueryNames>;
using ASTExistsDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDictionaryQueryIDAndQueryNames>;
using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateTableQueryIDAndQueryNames>;
......
......@@ -3,7 +3,9 @@ EXISTS TABLE db_01048.t_01048;
EXISTS DICTIONARY db_01048.t_01048;
DROP DATABASE IF EXISTS db_01048;
EXISTS DATABASE db_01048;
CREATE DATABASE db_01048;
EXISTS DATABASE db_01048;
DROP TABLE IF EXISTS db_01048.t_01048;
EXISTS db_01048.t_01048;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册