Merge branch 'support_exists_view_v3' of git://github.com/spongedu/ClickHouse into exists-view

This commit is contained in:
Anton Popov 2021-01-13 18:08:43 +03:00
commit 11f459ad03
6 changed files with 49 additions and 1 deletions

View File

@ -53,6 +53,13 @@ BlockInputStreamPtr InterpreterExistsQuery::executeImpl()
result = DatabaseCatalog::instance().isTableExist({database, exists_query->table}, context);
}
}
else if ((exists_query = query_ptr->as<ASTExistsViewQuery>()))
{
String database = context.resolveDatabase(exists_query->database);
context.checkAccess(AccessType::SHOW_TABLES, database, exists_query->table);
auto tbl = DatabaseCatalog::instance().tryGetTable({database, exists_query->table}, context);
result = tbl != nullptr && tbl->isView();
}
else if ((exists_query = query_ptr->as<ASTExistsDatabaseQuery>()))
{
String database = context.resolveDatabase(exists_query->database);

View File

@ -156,6 +156,10 @@ std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, Context &
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
else if (query->as<ASTExistsViewQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);
}
else if (query->as<ASTExistsDictionaryQuery>())
{
return std::make_unique<InterpreterExistsQuery>(query, context);

View File

@ -32,6 +32,7 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
bool parse_only_database_name = false;
bool parse_show_create_view = false;
bool exists_view = false;
bool temporary = false;
if (s_exists.ignore(pos, expected))
@ -41,6 +42,11 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
query = std::make_shared<ASTExistsDatabaseQuery>();
parse_only_database_name = true;
}
else if (s_view.ignore(pos, expected))
{
query = std::make_shared<ASTExistsViewQuery>();
exists_view = true;
}
else
{
if (s_temporary.ignore(pos, expected))
@ -86,7 +92,7 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
}
else
{
if (!parse_show_create_view)
if (!(exists_view || parse_show_create_view))
{
if (temporary || s_temporary.ignore(pos, expected))
query->temporary = true;

View File

@ -22,6 +22,15 @@ struct ASTExistsTableQueryIDAndQueryNames
static constexpr auto QueryTemporary = "EXISTS TEMPORARY TABLE";
};
struct ASTExistsViewQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsViewQuery";
static constexpr auto Query = "EXISTS VIEW";
/// No temporary view are supported, just for parsing
static constexpr auto QueryTemporary = "";
};
struct ASTExistsDictionaryQueryIDAndQueryNames
{
static constexpr auto ID = "ExistsDictionaryQuery";
@ -69,6 +78,7 @@ struct ASTDescribeQueryExistsQueryIDAndQueryNames
using ASTExistsDatabaseQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDatabaseQueryIDAndQueryNames>;
using ASTExistsTableQuery = ASTQueryWithTableAndOutputImpl<ASTExistsTableQueryIDAndQueryNames>;
using ASTExistsViewQuery = ASTQueryWithTableAndOutputImpl<ASTExistsViewQueryIDAndQueryNames>;
using ASTExistsDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDictionaryQueryIDAndQueryNames>;
using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateTableQueryIDAndQueryNames>;
using ASTShowCreateViewQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateViewQueryIDAndQueryNames>;

View File

@ -21,6 +21,13 @@
0
0
0
1
0
0
0
0
0
0
0
0
0

View File

@ -40,6 +40,20 @@ EXISTS db_01048.t_01048;
EXISTS TABLE db_01048.t_01048;
EXISTS DICTIONARY db_01048.t_01048;
CREATE TABLE db_01048.t_01048_2 (x UInt8) ENGINE = Memory;
CREATE VIEW db_01048.v_01048 AS SELECT * FROM db_01048.t_01048_2;
EXISTS VIEW db_01048.v_01048;
EXISTS VIEW db_01048.t_01048_2;
EXISTS VIEW db_01048.v_not_exist;
DROP VIEW db_01048.v_01048;
EXISTS VIEW db_01048.v_01048;
EXISTS VIEW db_01048.t_01048_2;
EXISTS VIEW db_01048.v_not_exist;
EXISTS VIEW db_not_exists.v_not_exist;
DROP TABLE db_01048.t_01048_2;
DROP DATABASE db_01048;
EXISTS db_01048.t_01048;
EXISTS TABLE db_01048.t_01048;