From ba7d324006f4c65d99753c564d6b7cfb61d717da Mon Sep 17 00:00:00 2001 From: ywqzzy <592838129@qq.com> Date: Wed, 6 Apr 2022 14:59:14 +0800 Subject: [PATCH] update. --- dbms/src/Interpreters/InterpreterFactory.cpp | 9 -- .../InterpreterShowCreateQuery.cpp | 82 -------------- .../Interpreters/InterpreterShowCreateQuery.h | 49 --------- dbms/src/Parsers/ParserQueryWithOutput.cpp | 20 ++-- .../Parsers/ParserTablePropertiesQuery.cpp | 103 ------------------ dbms/src/Parsers/ParserTablePropertiesQuery.h | 34 ------ dbms/src/Parsers/TablePropertiesQueriesASTs.h | 27 +---- 7 files changed, 9 insertions(+), 315 deletions(-) delete mode 100644 dbms/src/Interpreters/InterpreterShowCreateQuery.cpp delete mode 100644 dbms/src/Interpreters/InterpreterShowCreateQuery.h delete mode 100644 dbms/src/Parsers/ParserTablePropertiesQuery.cpp delete mode 100644 dbms/src/Parsers/ParserTablePropertiesQuery.h diff --git a/dbms/src/Interpreters/InterpreterFactory.cpp b/dbms/src/Interpreters/InterpreterFactory.cpp index 5231bbd3dd6..60ad9b5e767 100644 --- a/dbms/src/Interpreters/InterpreterFactory.cpp +++ b/dbms/src/Interpreters/InterpreterFactory.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -135,14 +134,6 @@ std::unique_ptr InterpreterFactory::get(ASTPtr & query, Context & { return std::make_unique(query, context); } - else if (typeid_cast(query.get())) - { - return std::make_unique(query, context); - } - else if (typeid_cast(query.get())) - { - return std::make_unique(query, context); - } else if (typeid_cast(query.get())) { return std::make_unique(query, context); diff --git a/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp b/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp deleted file mode 100644 index 5f0e9074314..00000000000 --- a/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace DB -{ -namespace ErrorCodes -{ -extern const int SYNTAX_ERROR; -extern const int THERE_IS_NO_QUERY; -} // namespace ErrorCodes - -BlockIO InterpreterShowCreateQuery::execute() -{ - BlockIO res; - res.in = executeImpl(); - return res; -} - - -Block InterpreterShowCreateQuery::getSampleBlock() -{ - return Block{{ColumnString::create(), - std::make_shared(), - "statement"}}; -} - - -BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() -{ - const auto & ast = dynamic_cast(*query_ptr); - - if (ast.temporary && !ast.database.empty()) - throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR); - - ASTPtr create_query; - if (ast.temporary) - create_query = context.getCreateExternalTableQuery(ast.table); - else if (ast.table.empty()) - create_query = context.getCreateDatabaseQuery(ast.database); - else - create_query = context.getCreateTableQuery(ast.database, ast.table); - - if (!create_query && ast.temporary) - throw Exception("Unable to show the create query of " + ast.table + ". Maybe it was created by the system.", ErrorCodes::THERE_IS_NO_QUERY); - - std::stringstream stream; - formatAST(*create_query, stream, false, true); - String res = stream.str(); - - MutableColumnPtr column = ColumnString::create(); - column->insert(res); - - return std::make_shared(Block{{std::move(column), - std::make_shared(), - "statement"}}); -} - -} // namespace DB diff --git a/dbms/src/Interpreters/InterpreterShowCreateQuery.h b/dbms/src/Interpreters/InterpreterShowCreateQuery.h deleted file mode 100644 index 50323477876..00000000000 --- a/dbms/src/Interpreters/InterpreterShowCreateQuery.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - - -namespace DB -{ -class Context; -class IAST; -using ASTPtr = std::shared_ptr; - - -/** Return single row with single column "statement" of type String with text of query to CREATE specified table. - */ -class InterpreterShowCreateQuery : public IInterpreter -{ -public: - InterpreterShowCreateQuery(const ASTPtr & query_ptr_, const Context & context_) - : query_ptr(query_ptr_) - , context(context_) - {} - - BlockIO execute() override; - - static Block getSampleBlock(); - -private: - ASTPtr query_ptr; - const Context & context; - - BlockInputStreamPtr executeImpl(); -}; - - -} // namespace DB diff --git a/dbms/src/Parsers/ParserQueryWithOutput.cpp b/dbms/src/Parsers/ParserQueryWithOutput.cpp index 174d70e3dae..2bdc83223b3 100644 --- a/dbms/src/Parsers/ParserQueryWithOutput.cpp +++ b/dbms/src/Parsers/ParserQueryWithOutput.cpp @@ -12,28 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include +#include #include #include +#include +#include +#include +#include +#include namespace DB { - bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserShowTablesQuery show_tables_p; ParserSelectWithUnionQuery select_p; - ParserTablePropertiesQuery table_p; ParserDescribeTableQuery describe_table_p; ParserShowProcesslistQuery show_processlist_p; ParserCreateQuery create_p; @@ -47,7 +44,6 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec bool parsed = select_p.parse(pos, query, expected) || show_tables_p.parse(pos, query, expected) - || table_p.parse(pos, query, expected) || describe_table_p.parse(pos, query, expected) || show_processlist_p.parse(pos, query, expected) || create_p.parse(pos, query, expected) @@ -89,4 +85,4 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec return true; } -} +} // namespace DB diff --git a/dbms/src/Parsers/ParserTablePropertiesQuery.cpp b/dbms/src/Parsers/ParserTablePropertiesQuery.cpp deleted file mode 100644 index 6402fdb8a14..00000000000 --- a/dbms/src/Parsers/ParserTablePropertiesQuery.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include -#include - -#include - - -namespace DB -{ - - -bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) -{ - ParserKeyword s_exists("EXISTS"); - ParserKeyword s_temporary("TEMPORARY"); - ParserKeyword s_describe("DESCRIBE"); - ParserKeyword s_desc("DESC"); - ParserKeyword s_show("SHOW"); - ParserKeyword s_create("CREATE"); - ParserKeyword s_database("DATABASE"); - ParserKeyword s_table("TABLE"); - ParserToken s_dot(TokenType::Dot); - ParserIdentifier name_p; - - ASTPtr database; - ASTPtr table; - std::shared_ptr query; - - bool parse_only_database_name = false; - - if (s_exists.ignore(pos, expected)) - { - query = std::make_shared(); - } - else if (s_show.ignore(pos, expected)) - { - if (!s_create.ignore(pos, expected)) - return false; - - if (s_database.ignore(pos, expected)) - { - parse_only_database_name = true; - query = std::make_shared(); - } - else - query = std::make_shared(); - } - else - { - return false; - } - - if (parse_only_database_name) - { - if (!name_p.parse(pos, database, expected)) - return false; - } - else - { - if (s_temporary.ignore(pos, expected)) - query->temporary = true; - - s_table.ignore(pos, expected); - - if (!name_p.parse(pos, table, expected)) - return false; - - if (s_dot.ignore(pos, expected)) - { - database = table; - if (!name_p.parse(pos, table, expected)) - return false; - } - } - - if (database) - query->database = typeid_cast(*database).name; - if (table) - query->table = typeid_cast(*table).name; - - node = query; - - return true; -} - - -} diff --git a/dbms/src/Parsers/ParserTablePropertiesQuery.h b/dbms/src/Parsers/ParserTablePropertiesQuery.h deleted file mode 100644 index eb36f177396..00000000000 --- a/dbms/src/Parsers/ParserTablePropertiesQuery.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include - - -namespace DB -{ - -/** Query (EXISTS | SHOW CREATE) [TABLE] [db.]name [FORMAT format] - */ -class ParserTablePropertiesQuery : public IParserBase -{ -protected: - const char * getName() const override { return "EXISTS or SHOW CREATE query"; } - bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; -}; - -} diff --git a/dbms/src/Parsers/TablePropertiesQueriesASTs.h b/dbms/src/Parsers/TablePropertiesQueriesASTs.h index 1c2502c4259..570cabf46ca 100644 --- a/dbms/src/Parsers/TablePropertiesQueriesASTs.h +++ b/dbms/src/Parsers/TablePropertiesQueriesASTs.h @@ -19,25 +19,12 @@ namespace DB { - struct ASTExistsQueryIDAndQueryNames { static constexpr auto ID = "ExistsQuery"; static constexpr auto Query = "EXISTS TABLE"; }; -struct ASTShowCreateTableQueryIDAndQueryNames -{ - static constexpr auto ID = "ShowCreateTableQuery"; - static constexpr auto Query = "SHOW CREATE TABLE"; -}; - -struct ASTShowCreateDatabaseQueryIDAndQueryNames -{ - static constexpr auto ID = "ShowCreateDatabaseQuery"; - static constexpr auto Query = "SHOW CREATE DATABASE"; -}; - struct ASTDescribeQueryExistsQueryIDAndQueryNames { static constexpr auto ID = "DescribeQuery"; @@ -45,17 +32,6 @@ struct ASTDescribeQueryExistsQueryIDAndQueryNames }; using ASTExistsQuery = ASTQueryWithTableAndOutputImpl; -using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl; - -class ASTShowCreateDatabaseQuery : public ASTQueryWithTableAndOutputImpl -{ -protected: - void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override - { - settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTShowCreateDatabaseQueryIDAndQueryNames::Query - << " " << (settings.hilite ? hilite_none : "") << backQuoteIfNeed(database); - } -}; class ASTDescribeQuery : public ASTQueryWithOutput { @@ -84,7 +60,6 @@ class ASTDescribeQuery : public ASTQueryWithOutput << "DESCRIBE TABLE " << (settings.hilite ? hilite_none : ""); table_expression->formatImpl(settings, state, frame); } - }; -} +} // namespace DB