Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitaisreal committed Mar 23, 2022
1 parent 355f49f commit 584929f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
19 changes: 11 additions & 8 deletions src/Interpreters/InterpreterExistsQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ QueryPipeline InterpreterExistsQuery::executeImpl()
result = DatabaseCatalog::instance().isTableExist({database, exists_query->getTable()}, getContext());
}
}
else if ((exists_query = query_ptr->as<ASTExistsViewQuery>()))
else if (auto * exists_view_query = query_ptr->as<ASTExistsViewQuery>())
{
String database = getContext()->resolveDatabase(exists_query->getDatabase());
getContext()->checkAccess(AccessType::SHOW_TABLES, database, exists_query->getTable());
auto table = DatabaseCatalog::instance().tryGetTable({database, exists_query->getTable()}, getContext());
if (exists_query->materialized) {
String database = getContext()->resolveDatabase(exists_view_query->getDatabase());
getContext()->checkAccess(AccessType::SHOW_TABLES, database, exists_view_query->getTable());
auto table = DatabaseCatalog::instance().tryGetTable({database, exists_view_query->getTable()}, getContext());
if (exists_view_query->materialized)
{
result = table && table->isView() && table->getName() == "MaterializedView";
}
else if (exists_query->live) {
else if (exists_view_query->live)
{
result = table && table->isView() && table->getName() == "LiveView";
}
else if (exists_query->window) {
result = table && table->isView() && table->getName() == "";
else if (exists_view_query->window)
{
result = table && table->isView() && table->getName() == "WindowView";
}
else
{
Expand Down
4 changes: 0 additions & 4 deletions src/Parsers/ASTQueryWithTableAndOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
UUID uuid = UUIDHelpers::Nil;
bool temporary{false};

bool materialized;
bool live;
bool window;

String getDatabase() const;
String getTable() const;

Expand Down
15 changes: 9 additions & 6 deletions src/Parsers/ParserTablePropertiesQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
{
if (s_view.ignore(pos, expected))
{
query = std::make_shared<ASTExistsViewQuery>();
query->materialized = true;
auto exists_query = std::make_shared<ASTExistsViewQuery>();
exists_query->materialized = true;
exists_view = true;
query = std::move(exists_query);
}
else
{
Expand All @@ -61,9 +62,10 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
{
if (s_view.ignore(pos, expected))
{
query = std::make_shared<ASTExistsViewQuery>();
query->live = true;
auto exists_query = std::make_shared<ASTExistsViewQuery>();
exists_query->live = true;
exists_view = true;
query = std::move(exists_query);
}
else
{
Expand All @@ -74,9 +76,10 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
{
if (s_view.ignore(pos, expected))
{
auto exists_query = std::make_shared<ASTExistsViewQuery>();
exists_query->window = true;
query = std::make_shared<ASTExistsViewQuery>();
query->window = true;
exists_view = true;
query = std::move(exists_query);
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/Parsers/TablePropertiesQueriesASTs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreat

class ASTExistsViewQuery : public ASTQueryWithTableAndOutputImpl<ASTExistsViewQueryIDAndQueryNames>
{
public:
bool materialized = false;
bool live = false;
bool window = false;
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
Expand Down
11 changes: 0 additions & 11 deletions tests/queries/0_stateless/01048_exists_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ EXISTS VIEW db_01048.v_not_exist;
EXISTS VIEW db_not_exists.v_not_exist;
DROP TABLE db_01048.t_01048_2;

CREATE TABLE db_01048.t_01048_3 (x UInt8) ENGINE = Memory;
CREATE MATERIALIZED VIEW db_01048.v_01048 ENGINE = Memory AS SELECT * FROM db_01048.t_01048_3;
EXISTS VIEW db_01048.v_01048;
EXISTS MATERIALIZED VIEW db_01048.v_01048;
EXISTS LIVE VIEW db_01048.v_01048;
DROP VIEW db_01048.v_01048;
EXISTS VIEW db_01048.v_01048;
EXISTS MATERIALIZED VIEW db_01048.v_01048;
EXISTS LIVE VIEW db_01048.v_01048;
DROP TABLE db_01048.t_01048_3;

DROP DATABASE db_01048;
EXISTS db_01048.t_01048;
EXISTS TABLE db_01048.t_01048;
Expand Down
6 changes: 6 additions & 0 deletions tests/queries/0_stateless/02243_exists_view_query.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1
1
0
0
0
0
17 changes: 17 additions & 0 deletions tests/queries/0_stateless/02243_exists_view_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (x UInt8) ENGINE = TinyLog;

DROP VIEW IF EXISTS materialized_view;
CREATE MATERIALIZED VIEW materialized_view ENGINE = TinyLog AS SELECT * FROM test_table;

EXISTS VIEW materialized_view;
EXISTS MATERIALIZED VIEW materialized_view;
EXISTS LIVE VIEW materialized_view;

DROP VIEW materialized_view;

EXISTS VIEW materialized_view;
EXISTS MATERIALIZED VIEW materialized_view;
EXISTS LIVE VIEW materialized_view;

DROP TABLE test_table;

0 comments on commit 584929f

Please sign in to comment.