support EXISTS DATABASE syntax

This commit is contained in:
spongedc 2020-12-24 17:16:47 +08:00
parent a58acbae67
commit 71ab8c18fa
6 changed files with 39 additions and 8 deletions

View File

@ -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)

View File

@ -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);

View File

@ -33,6 +33,13 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
bool temporary = false;
if (s_exists.ignore(pos, expected))
{
if (s_database.ignore(pos, expected))
{
query = std::make_shared<ASTExistsDatabaseQuery>();
parse_only_database_name = true;
}
else
{
if (s_temporary.ignore(pos, expected))
temporary = true;
@ -44,6 +51,7 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
else
query = std::make_shared<ASTExistsTableQuery>();
}
}
else if (s_show.ignore(pos, expected))
{
if (!s_create.ignore(pos, expected))

View File

@ -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>;

View File

@ -2,6 +2,8 @@
0
0
0
1
0
0
0
1

View File

@ -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;