From 8b2feaeca24b15415a707daba6494b06cb780292 Mon Sep 17 00:00:00 2001 From: spongedc Date: Mon, 14 Dec 2020 22:37:25 +0800 Subject: [PATCH 1/7] Support SHOW CREATE VIEW Syntax --- src/Common/ErrorCodes.cpp | 1 + src/Databases/IDatabase.h | 1 + src/Interpreters/InterpreterFactory.cpp | 4 +++ .../InterpreterShowCreateQuery.cpp | 9 ++++++- src/Parsers/ASTCreateQuery.h | 2 ++ src/Parsers/ParserTablePropertiesQuery.cpp | 20 +++++++++----- src/Parsers/ParserTablePropertiesQuery.h | 2 +- src/Parsers/TablePropertiesQueriesASTs.h | 9 +++++++ .../01602_show_create_view.reference | 3 +++ .../0_stateless/01602_show_create_view.sql | 26 +++++++++++++++++++ 10 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 tests/queries/0_stateless/01602_show_create_view.reference create mode 100644 tests/queries/0_stateless/01602_show_create_view.sql diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index 1e381808d16..328d0a364ff 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -529,6 +529,7 @@ M(560, ZSTD_ENCODER_FAILED) \ M(561, ZSTD_DECODER_FAILED) \ M(562, TLD_LIST_NOT_FOUND) \ + M(563, NOT_VIEW) \ \ M(999, KEEPER_EXCEPTION) \ M(1000, POCO_EXCEPTION) \ diff --git a/src/Databases/IDatabase.h b/src/Databases/IDatabase.h index fadec5fe7a9..fb2a9652d4b 100644 --- a/src/Databases/IDatabase.h +++ b/src/Databases/IDatabase.h @@ -30,6 +30,7 @@ namespace ErrorCodes extern const int NOT_IMPLEMENTED; extern const int CANNOT_GET_CREATE_TABLE_QUERY; extern const int CANNOT_GET_CREATE_DICTIONARY_QUERY; + extern const int NOT_VIEW; } class IDatabaseTablesIterator diff --git a/src/Interpreters/InterpreterFactory.cpp b/src/Interpreters/InterpreterFactory.cpp index 30992905f5d..156c3c1ba51 100644 --- a/src/Interpreters/InterpreterFactory.cpp +++ b/src/Interpreters/InterpreterFactory.cpp @@ -160,6 +160,10 @@ std::unique_ptr InterpreterFactory::get(ASTPtr & query, Context & { return std::make_unique(query, context); } + else if (query->as()) + { + return std::make_unique(query, context); + } else if (query->as()) { return std::make_unique(query, context); diff --git a/src/Interpreters/InterpreterShowCreateQuery.cpp b/src/Interpreters/InterpreterShowCreateQuery.cpp index 907523ce94b..bcf6cc09473 100644 --- a/src/Interpreters/InterpreterShowCreateQuery.cpp +++ b/src/Interpreters/InterpreterShowCreateQuery.cpp @@ -43,12 +43,19 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { ASTPtr create_query; ASTQueryWithTableAndOutput * show_query; - if ((show_query = query_ptr->as())) + if ((show_query = query_ptr->as()) || + (show_query = query_ptr->as())) { auto resolve_table_type = show_query->temporary ? Context::ResolveExternal : Context::ResolveOrdinary; auto table_id = context.resolveStorageID(*show_query, resolve_table_type); context.checkAccess(AccessType::SHOW_COLUMNS, table_id); create_query = DatabaseCatalog::instance().getDatabase(table_id.database_name)->getCreateTableQuery(table_id.table_name, context); + if (query_ptr->as()) + { + auto & ast_create_query = create_query->as(); + if (!ast_create_query.isView()) + throw Exception("'" + ast_create_query.database + "." + ast_create_query.table +"' is not VIEW", ErrorCodes::NOT_VIEW); + } } else if ((show_query = query_ptr->as())) { diff --git a/src/Parsers/ASTCreateQuery.h b/src/Parsers/ASTCreateQuery.h index 7b2deb99698..67ad9a89392 100644 --- a/src/Parsers/ASTCreateQuery.h +++ b/src/Parsers/ASTCreateQuery.h @@ -91,6 +91,8 @@ public: return removeOnCluster(clone(), new_database); } + bool isView() { return is_view || is_materialized_view || is_live_view; } + protected: void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; }; diff --git a/src/Parsers/ParserTablePropertiesQuery.cpp b/src/Parsers/ParserTablePropertiesQuery.cpp index 2ee85a3330d..fcb7c8ef7a4 100644 --- a/src/Parsers/ParserTablePropertiesQuery.cpp +++ b/src/Parsers/ParserTablePropertiesQuery.cpp @@ -21,6 +21,7 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & ParserKeyword s_create("CREATE"); ParserKeyword s_database("DATABASE"); ParserKeyword s_table("TABLE"); + ParserKeyword s_view("VIEW"); ParserKeyword s_dictionary("DICTIONARY"); ParserToken s_dot(TokenType::Dot); ParserIdentifier name_p; @@ -30,6 +31,7 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & std::shared_ptr query; bool parse_only_database_name = false; + bool parse_show_create_view = false; bool temporary = false; if (s_exists.ignore(pos, expected)) @@ -56,6 +58,11 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & } else if (s_dictionary.checkWithoutMoving(pos, expected)) query = std::make_shared(); + else if (s_view.ignore(pos, expected)) + { + query = std::make_shared(); + parse_show_create_view = true; + } else query = std::make_shared(); } @@ -71,15 +78,16 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & } else { - if (temporary || s_temporary.ignore(pos, expected)) - query->temporary = true; - - if (!s_table.ignore(pos, expected)) - s_dictionary.ignore(pos, expected); + if (!parse_show_create_view) + { + if (temporary || s_temporary.ignore(pos, expected)) + query->temporary = true; + if (!s_table.ignore(pos, expected)) + s_dictionary.ignore(pos, expected); + } if (!name_p.parse(pos, table, expected)) return false; - if (s_dot.ignore(pos, expected)) { database = table; diff --git a/src/Parsers/ParserTablePropertiesQuery.h b/src/Parsers/ParserTablePropertiesQuery.h index 5de4c45db88..8d2c26d34ab 100644 --- a/src/Parsers/ParserTablePropertiesQuery.h +++ b/src/Parsers/ParserTablePropertiesQuery.h @@ -7,7 +7,7 @@ namespace DB { -/** Query (EXISTS | SHOW CREATE) [TABLE|DICTIONARY] [db.]name [FORMAT format] +/** Query (EXISTS | SHOW CREATE) [DATABASE|TABLE|DICTIONARY] [db.]name [FORMAT format] */ class ParserTablePropertiesQuery : public IParserBase { diff --git a/src/Parsers/TablePropertiesQueriesASTs.h b/src/Parsers/TablePropertiesQueriesASTs.h index 6a8e3b2ce83..cbb9b2a382c 100644 --- a/src/Parsers/TablePropertiesQueriesASTs.h +++ b/src/Parsers/TablePropertiesQueriesASTs.h @@ -29,6 +29,14 @@ struct ASTShowCreateTableQueryIDAndQueryNames static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY TABLE"; }; +struct ASTShowCreateViewQueryIDAndQueryNames +{ + static constexpr auto ID = "ShowCreateViewQuery"; + static constexpr auto Query = "SHOW CREATE VIEW"; + /// No temporary view are supported, just for parsing + static constexpr auto QueryTemporary = ""; +}; + struct ASTShowCreateDatabaseQueryIDAndQueryNames { static constexpr auto ID = "ShowCreateDatabaseQuery"; @@ -54,6 +62,7 @@ struct ASTDescribeQueryExistsQueryIDAndQueryNames using ASTExistsTableQuery = ASTQueryWithTableAndOutputImpl; using ASTExistsDictionaryQuery = ASTQueryWithTableAndOutputImpl; using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl; +using ASTShowCreateViewQuery = ASTQueryWithTableAndOutputImpl; using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl; class ASTShowCreateDatabaseQuery : public ASTQueryWithTableAndOutputImpl diff --git a/tests/queries/0_stateless/01602_show_create_view.reference b/tests/queries/0_stateless/01602_show_create_view.reference new file mode 100644 index 00000000000..2c2ba13bef3 --- /dev/null +++ b/tests/queries/0_stateless/01602_show_create_view.reference @@ -0,0 +1,3 @@ +CREATE VIEW test_1602.v\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl +CREATE MATERIALIZED VIEW test_1602.vv\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n)\nENGINE = MergeTree\nPARTITION BY toYYYYMM(EventDate)\nORDER BY (CounterID, EventDate, intHash32(UserID))\nSETTINGS index_granularity = 8192 AS\nSELECT *\nFROM test_1602.tbl +CREATE LIVE VIEW test_1602.vvv\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl diff --git a/tests/queries/0_stateless/01602_show_create_view.sql b/tests/queries/0_stateless/01602_show_create_view.sql new file mode 100644 index 00000000000..0a4ecd4ceec --- /dev/null +++ b/tests/queries/0_stateless/01602_show_create_view.sql @@ -0,0 +1,26 @@ +DROP DATABASE IF EXISTS test_1602; + +CREATE DATABASE test_1602; + +CREATE TABLE test_1602.tbl (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192; + +CREATE VIEW test_1602.v AS SELECT * FROM test_1602.tbl; + +CREATE MATERIALIZED VIEW test_1602.vv (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192 AS SELECT * FROM test_1602.tbl; + + +SET allow_experimental_live_view=1; + +CREATE LIVE VIEW test_1602.vvv AS SELECT * FROM test_1602.tbl; + +SHOW CREATE VIEW test_1602.v; + +SHOW CREATE VIEW test_1602.vv; + +SHOW CREATE VIEW test_1602.vvv; + +SHOW CREATE VIEW test_1602.not_exist_view; -- { serverError 390 } + +SHOW CREATE VIEW test_1602.tbl; -- { serverError 563 } + +DROP DATABASE IF EXISTS test_1602; From dc27e0a4fd152c1d1b24cf32af2e080d7fa7cd96 Mon Sep 17 00:00:00 2001 From: spongedc Date: Tue, 15 Dec 2020 20:29:26 +0800 Subject: [PATCH 2/7] Fix error code --- src/Common/ErrorCodes.cpp | 1 - src/Databases/IDatabase.h | 1 - src/Interpreters/InterpreterShowCreateQuery.cpp | 2 +- tests/queries/0_stateless/01602_show_create_view.sql | 5 ++--- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index 328d0a364ff..1e381808d16 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -529,7 +529,6 @@ M(560, ZSTD_ENCODER_FAILED) \ M(561, ZSTD_DECODER_FAILED) \ M(562, TLD_LIST_NOT_FOUND) \ - M(563, NOT_VIEW) \ \ M(999, KEEPER_EXCEPTION) \ M(1000, POCO_EXCEPTION) \ diff --git a/src/Databases/IDatabase.h b/src/Databases/IDatabase.h index fb2a9652d4b..fadec5fe7a9 100644 --- a/src/Databases/IDatabase.h +++ b/src/Databases/IDatabase.h @@ -30,7 +30,6 @@ namespace ErrorCodes extern const int NOT_IMPLEMENTED; extern const int CANNOT_GET_CREATE_TABLE_QUERY; extern const int CANNOT_GET_CREATE_DICTIONARY_QUERY; - extern const int NOT_VIEW; } class IDatabaseTablesIterator diff --git a/src/Interpreters/InterpreterShowCreateQuery.cpp b/src/Interpreters/InterpreterShowCreateQuery.cpp index bcf6cc09473..869573f0d66 100644 --- a/src/Interpreters/InterpreterShowCreateQuery.cpp +++ b/src/Interpreters/InterpreterShowCreateQuery.cpp @@ -54,7 +54,7 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { auto & ast_create_query = create_query->as(); if (!ast_create_query.isView()) - throw Exception("'" + ast_create_query.database + "." + ast_create_query.table +"' is not VIEW", ErrorCodes::NOT_VIEW); + throw Exception("'" + ast_create_query.database + "." + ast_create_query.table +"' is not VIEW", ErrorCodes::BAD_ARGUMENTS); } } else if ((show_query = query_ptr->as())) diff --git a/tests/queries/0_stateless/01602_show_create_view.sql b/tests/queries/0_stateless/01602_show_create_view.sql index 0a4ecd4ceec..8e049d2d4cd 100644 --- a/tests/queries/0_stateless/01602_show_create_view.sql +++ b/tests/queries/0_stateless/01602_show_create_view.sql @@ -4,8 +4,7 @@ CREATE DATABASE test_1602; CREATE TABLE test_1602.tbl (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192; -CREATE VIEW test_1602.v AS SELECT * FROM test_1602.tbl; - +CREATE VIEW test_1602.v AS SELECT * FROM test_1602.tbl; CREATE MATERIALIZED VIEW test_1602.vv (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192 AS SELECT * FROM test_1602.tbl; @@ -21,6 +20,6 @@ SHOW CREATE VIEW test_1602.vvv; SHOW CREATE VIEW test_1602.not_exist_view; -- { serverError 390 } -SHOW CREATE VIEW test_1602.tbl; -- { serverError 563 } +SHOW CREATE VIEW test_1602.tbl; -- { serverError 36 } DROP DATABASE IF EXISTS test_1602; From bf096097cbdeb80555ad03d7592d24e690ea711b Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Tue, 15 Dec 2020 21:56:06 +0300 Subject: [PATCH 3/7] Update InterpreterShowCreateQuery.cpp --- src/Interpreters/InterpreterShowCreateQuery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interpreters/InterpreterShowCreateQuery.cpp b/src/Interpreters/InterpreterShowCreateQuery.cpp index 869573f0d66..e4f30c30cfb 100644 --- a/src/Interpreters/InterpreterShowCreateQuery.cpp +++ b/src/Interpreters/InterpreterShowCreateQuery.cpp @@ -54,7 +54,7 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { auto & ast_create_query = create_query->as(); if (!ast_create_query.isView()) - throw Exception("'" + ast_create_query.database + "." + ast_create_query.table +"' is not VIEW", ErrorCodes::BAD_ARGUMENTS); + throw Exception(backQuote(ast_create_query.database) + "." + backQuote(ast_create_query.table) + " is not a VIEW", ErrorCodes::BAD_ARGUMENTS); } } else if ((show_query = query_ptr->as())) From 81b0fa298992d42fe4df6a934ae6e90f21eacf51 Mon Sep 17 00:00:00 2001 From: spongedc Date: Wed, 16 Dec 2020 11:19:38 +0800 Subject: [PATCH 4/7] 1. rename is_view to is_ordinary_view 2. add more tests --- src/Interpreters/InterpreterCreateQuery.cpp | 6 +++--- src/Parsers/ASTCreateQuery.h | 2 +- src/Parsers/ParserCreateQuery.cpp | 6 +++--- src/Storages/StorageFactory.cpp | 2 +- tests/queries/0_stateless/01602_show_create_view.sql | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index d57a14a61dc..8f3d5086b6b 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -593,7 +593,7 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const if (create.as_table_function) return; - if (create.storage || create.is_view || create.is_materialized_view || create.is_live_view || create.is_dictionary) + if (create.storage || create.is_dictionary || create.isView()) { if (create.temporary && create.storage && create.storage->engine && create.storage->engine->name != "Memory") throw Exception( @@ -748,7 +748,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) if (create.to_table_id && create.to_table_id.database_name.empty()) create.to_table_id.database_name = current_database; - if (create.select && (create.is_view || create.is_materialized_view || create.is_live_view)) + if (create.select && create.isView()) { AddDefaultDatabaseVisitor visitor(current_database); visitor.visit(*create.select); @@ -884,7 +884,7 @@ BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create) { /// If the query is a CREATE SELECT, insert the data into the table. if (create.select && !create.attach - && !create.is_view && !create.is_live_view && (!create.is_materialized_view || create.is_populate)) + && !create.is_ordinary_view && !create.is_live_view && (!create.is_materialized_view || create.is_populate)) { auto insert = std::make_shared(); insert->table_id = {create.database, create.table, create.uuid}; diff --git a/src/Parsers/ASTCreateQuery.h b/src/Parsers/ASTCreateQuery.h index 67ad9a89392..ee178b74460 100644 --- a/src/Parsers/ASTCreateQuery.h +++ b/src/Parsers/ASTCreateQuery.h @@ -57,7 +57,7 @@ class ASTCreateQuery : public ASTQueryWithTableAndOutput, public ASTQueryWithOnC public: bool attach{false}; /// Query ATTACH TABLE, not CREATE TABLE. bool if_not_exists{false}; - bool is_view{false}; + bool is_ordinary_view{false}; bool is_materialized_view{false}; bool is_live_view{false}; bool is_populate{false}; diff --git a/src/Parsers/ParserCreateQuery.cpp b/src/Parsers/ParserCreateQuery.cpp index b08646bcf9d..262ddb09398 100644 --- a/src/Parsers/ParserCreateQuery.cpp +++ b/src/Parsers/ParserCreateQuery.cpp @@ -735,7 +735,7 @@ bool ParserCreateViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec String cluster_str; bool attach = false; bool if_not_exists = false; - bool is_view = false; + bool is_ordinary_view = false; bool is_materialized_view = false; bool is_populate = false; bool replace_view = false; @@ -759,7 +759,7 @@ bool ParserCreateViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec is_materialized_view = true; } else - is_view = true; + is_ordinary_view = true; if (!s_view.ignore(pos, expected)) return false; @@ -816,7 +816,7 @@ bool ParserCreateViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec query->attach = attach; query->if_not_exists = if_not_exists; - query->is_view = is_view; + query->is_ordinary_view = is_ordinary_view; query->is_materialized_view = is_materialized_view; query->is_populate = is_populate; query->replace_view = replace_view; diff --git a/src/Storages/StorageFactory.cpp b/src/Storages/StorageFactory.cpp index eda9f36010f..93982c2f3a3 100644 --- a/src/Storages/StorageFactory.cpp +++ b/src/Storages/StorageFactory.cpp @@ -53,7 +53,7 @@ StoragePtr StorageFactory::get( bool has_engine_args = false; - if (query.is_view) + if (query.is_ordinary_view) { if (query.storage) throw Exception("Specifying ENGINE is not allowed for a View", ErrorCodes::INCORRECT_QUERY); diff --git a/tests/queries/0_stateless/01602_show_create_view.sql b/tests/queries/0_stateless/01602_show_create_view.sql index 8e049d2d4cd..855ccf58562 100644 --- a/tests/queries/0_stateless/01602_show_create_view.sql +++ b/tests/queries/0_stateless/01602_show_create_view.sql @@ -22,4 +22,6 @@ SHOW CREATE VIEW test_1602.not_exist_view; -- { serverError 390 } SHOW CREATE VIEW test_1602.tbl; -- { serverError 36 } +SHOW CREATE TEMPORARY VIEW; -- { serverError 60 } + DROP DATABASE IF EXISTS test_1602; From a0083e23d68a2047323b469e7cc146c25d6fc389 Mon Sep 17 00:00:00 2001 From: spongedc Date: Wed, 16 Dec 2020 12:07:50 +0800 Subject: [PATCH 5/7] Fix compile error --- src/Databases/DatabaseOnDisk.cpp | 2 +- src/Interpreters/InterpreterCreateQuery.cpp | 4 ++-- src/Parsers/ASTCreateQuery.cpp | 2 +- src/Parsers/ASTCreateQuery.h | 2 +- src/Parsers/New/AST/CreateViewQuery.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Databases/DatabaseOnDisk.cpp b/src/Databases/DatabaseOnDisk.cpp index 1e6b4019c4b..7fb91e1d074 100644 --- a/src/Databases/DatabaseOnDisk.cpp +++ b/src/Databases/DatabaseOnDisk.cpp @@ -111,7 +111,7 @@ String getObjectDefinitionFromCreateQuery(const ASTPtr & query) create->replace_view = false; /// For views it is necessary to save the SELECT query itself, for the rest - on the contrary - if (!create->is_view && !create->is_materialized_view && !create->is_live_view) + if (!create->isView()) create->select = nullptr; create->format = nullptr; diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 8f3d5086b6b..0f158eb757d 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -624,7 +624,7 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const const String qualified_name = backQuoteIfNeed(as_database_name) + "." + backQuoteIfNeed(as_table_name); - if (as_create.is_view) + if (as_create.is_ordinary_view) throw Exception( "Cannot CREATE a table AS " + qualified_name + ", it is a View", ErrorCodes::INCORRECT_QUERY); @@ -1030,7 +1030,7 @@ AccessRightsElements InterpreterCreateQuery::getRequiredAccess() const { required_access.emplace_back(AccessType::CREATE_DICTIONARY, create.database, create.table); } - else if (create.is_view || create.is_materialized_view || create.is_live_view) + else if (create.isView()) { if (create.temporary) required_access.emplace_back(AccessType::CREATE_TEMPORARY_TABLE); diff --git a/src/Parsers/ASTCreateQuery.cpp b/src/Parsers/ASTCreateQuery.cpp index 03db54c6957..4cb512fee20 100644 --- a/src/Parsers/ASTCreateQuery.cpp +++ b/src/Parsers/ASTCreateQuery.cpp @@ -231,7 +231,7 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat if (!is_dictionary) { std::string what = "TABLE"; - if (is_view) + if (is_ordinary_view) what = "VIEW"; if (is_materialized_view) what = "MATERIALIZED VIEW"; diff --git a/src/Parsers/ASTCreateQuery.h b/src/Parsers/ASTCreateQuery.h index ee178b74460..4dc895a5774 100644 --- a/src/Parsers/ASTCreateQuery.h +++ b/src/Parsers/ASTCreateQuery.h @@ -91,7 +91,7 @@ public: return removeOnCluster(clone(), new_database); } - bool isView() { return is_view || is_materialized_view || is_live_view; } + bool isView() const { return is_ordinary_view || is_materialized_view || is_live_view; } protected: void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; diff --git a/src/Parsers/New/AST/CreateViewQuery.cpp b/src/Parsers/New/AST/CreateViewQuery.cpp index df68687eb13..e558a141ca9 100644 --- a/src/Parsers/New/AST/CreateViewQuery.cpp +++ b/src/Parsers/New/AST/CreateViewQuery.cpp @@ -35,7 +35,7 @@ ASTPtr CreateViewQuery::convertToOld() const query->attach = attach; query->replace_view = replace; query->if_not_exists = if_not_exists; - query->is_view = true; + query->is_ordinary_view = true; query->cluster = cluster_name; if (has(SCHEMA)) query->set(query->columns_list, get(SCHEMA)->convertToOld()); From bcaccab0ff35e5280a014e5a0e899321a7f057c9 Mon Sep 17 00:00:00 2001 From: spongedc Date: Thu, 17 Dec 2020 11:28:18 +0800 Subject: [PATCH 6/7] 1. Fix test error 2. Add more test cases --- .../01083_expressions_in_engine_arguments.sql | 2 +- .../01602_show_create_view.reference | 4 ++++ .../0_stateless/01602_show_create_view.sql | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/01083_expressions_in_engine_arguments.sql b/tests/queries/0_stateless/01083_expressions_in_engine_arguments.sql index 22aa4434f19..e8ea12f9f9f 100644 --- a/tests/queries/0_stateless/01083_expressions_in_engine_arguments.sql +++ b/tests/queries/0_stateless/01083_expressions_in_engine_arguments.sql @@ -59,7 +59,7 @@ SHOW CREATE distributed; SHOW CREATE distributed_tf; SHOW CREATE url; SHOW CREATE rich_syntax; -SHOW CREATE view; +SHOW CREATE VIEW view; SHOW CREATE dict; INSERT INTO buffer VALUES (1); diff --git a/tests/queries/0_stateless/01602_show_create_view.reference b/tests/queries/0_stateless/01602_show_create_view.reference index 2c2ba13bef3..5d4bd2cd972 100644 --- a/tests/queries/0_stateless/01602_show_create_view.reference +++ b/tests/queries/0_stateless/01602_show_create_view.reference @@ -1,3 +1,7 @@ CREATE VIEW test_1602.v\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl CREATE MATERIALIZED VIEW test_1602.vv\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n)\nENGINE = MergeTree\nPARTITION BY toYYYYMM(EventDate)\nORDER BY (CounterID, EventDate, intHash32(UserID))\nSETTINGS index_granularity = 8192 AS\nSELECT *\nFROM test_1602.tbl CREATE LIVE VIEW test_1602.vvv\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl +CREATE VIEW test_1602.VIEW\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl +CREATE VIEW test_1602.DATABASE\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl +CREATE VIEW test_1602.DICTIONARY\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl +CREATE VIEW test_1602.TABLE\n(\n `EventDate` DateTime,\n `CounterID` UInt32,\n `UserID` UInt32\n) AS\nSELECT *\nFROM test_1602.tbl diff --git a/tests/queries/0_stateless/01602_show_create_view.sql b/tests/queries/0_stateless/01602_show_create_view.sql index 855ccf58562..fd5bf70d470 100644 --- a/tests/queries/0_stateless/01602_show_create_view.sql +++ b/tests/queries/0_stateless/01602_show_create_view.sql @@ -5,8 +5,16 @@ CREATE DATABASE test_1602; CREATE TABLE test_1602.tbl (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192; CREATE VIEW test_1602.v AS SELECT * FROM test_1602.tbl; + +CREATE VIEW test_1602.DATABASE AS SELECT * FROM test_1602.tbl; + +CREATE VIEW test_1602.DICTIONARY AS SELECT * FROM test_1602.tbl; + +CREATE VIEW test_1602.TABLE AS SELECT * FROM test_1602.tbl; + CREATE MATERIALIZED VIEW test_1602.vv (`EventDate` DateTime, `CounterID` UInt32, `UserID` UInt32) ENGINE = MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SETTINGS index_granularity = 8192 AS SELECT * FROM test_1602.tbl; +CREATE VIEW test_1602.VIEW AS SELECT * FROM test_1602.tbl; SET allow_experimental_live_view=1; @@ -24,4 +32,20 @@ SHOW CREATE VIEW test_1602.tbl; -- { serverError 36 } SHOW CREATE TEMPORARY VIEW; -- { serverError 60 } +SHOW CREATE VIEW; -- { clientError 62 } + +SHOW CREATE DATABASE; -- { clientError 62 } + +SHOW CREATE DICTIONARY; -- { clientError 62 } + +SHOW CREATE TABLE; -- { clientError 62 } + +SHOW CREATE test_1602.VIEW; + +SHOW CREATE test_1602.DATABASE; + +SHOW CREATE test_1602.DICTIONARY; + +SHOW CREATE test_1602.TABLE; + DROP DATABASE IF EXISTS test_1602; From 5425fa4dd2f22d3266f164c695c0ee483686fc67 Mon Sep 17 00:00:00 2001 From: spongedc Date: Thu, 17 Dec 2020 12:27:04 +0800 Subject: [PATCH 7/7] Fix style check fail --- src/Interpreters/InterpreterShowCreateQuery.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Interpreters/InterpreterShowCreateQuery.cpp b/src/Interpreters/InterpreterShowCreateQuery.cpp index e4f30c30cfb..10c8339c135 100644 --- a/src/Interpreters/InterpreterShowCreateQuery.cpp +++ b/src/Interpreters/InterpreterShowCreateQuery.cpp @@ -20,6 +20,7 @@ namespace ErrorCodes { extern const int SYNTAX_ERROR; extern const int THERE_IS_NO_QUERY; + extern const int BAD_ARGUMENTS; } BlockIO InterpreterShowCreateQuery::execute()