mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
support EXISTS DATABASE syntax
This commit is contained in:
parent
a58acbae67
commit
71ab8c18fa
@ -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>;
|
||||
|
@ -2,6 +2,8 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user