diff --git a/dbms/src/Interpreters/InterpreterCheckQuery.cpp b/dbms/src/Interpreters/InterpreterCheckQuery.cpp deleted file mode 100644 index 9aa5079c9d8..00000000000 --- a/dbms/src/Interpreters/InterpreterCheckQuery.cpp +++ /dev/null @@ -1,124 +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 - -#include -#include - -namespace DB -{ -namespace ErrorCodes -{ -extern const int INVALID_BLOCK_EXTRA_INFO; -extern const int RECEIVED_EMPTY_DATA; -} // namespace ErrorCodes - - -namespace -{ -/// A helper structure for performing a response to a DESCRIBE TABLE query with a Distributed table. -/// Contains information about the local table that was retrieved from a single replica. -struct TableDescription -{ - TableDescription(const Block & block, const BlockExtraInfo & extra_info_) - : extra_info(extra_info_) - { - const auto & name_column = typeid_cast(*block.getByName("name").column); - const auto & type_column = typeid_cast(*block.getByName("type").column); - const auto & default_type_column = typeid_cast(*block.getByName("default_type").column); - const auto & default_expression_column = typeid_cast(*block.getByName("default_expression").column); - - size_t row_count = block.rows(); - - names_with_types.reserve(name_column.byteSize() + type_column.byteSize() + (3 * row_count)); - - SHA512_CTX ctx; - SHA512_Init(&ctx); - - bool is_first = true; - for (size_t i = 0; i < row_count; ++i) - { - const auto & name = name_column.getDataAt(i).toString(); - const auto & type = type_column.getDataAt(i).toString(); - const auto & default_type = default_type_column.getDataAt(i).toString(); - const auto & default_expression = default_expression_column.getDataAt(i).toString(); - - names_with_types.append(is_first ? "" : ", "); - names_with_types.append(name); - names_with_types.append(" "); - names_with_types.append(type); - - SHA512_Update(&ctx, reinterpret_cast(name.data()), name.size()); - SHA512_Update(&ctx, reinterpret_cast(type.data()), type.size()); - SHA512_Update(&ctx, reinterpret_cast(default_type.data()), default_type.size()); - SHA512_Update(&ctx, reinterpret_cast(default_expression.data()), default_expression.size()); - - is_first = false; - } - - SHA512_Final(hash.data(), &ctx); - } - - using Hash = std::array; - - BlockExtraInfo extra_info; - std::string names_with_types; - Hash hash; - UInt32 structure_class; -}; - -using TableDescriptions = std::deque; - -} // namespace - -InterpreterCheckQuery::InterpreterCheckQuery(const ASTPtr & query_ptr_, const Context & context_) - : query_ptr(query_ptr_) - , context(context_) -{ -} - - -BlockIO InterpreterCheckQuery::execute() -{ - ASTCheckQuery & alter = typeid_cast(*query_ptr); - String & table_name = alter.table; - String database_name = alter.database.empty() ? context.getCurrentDatabase() : alter.database; - - StoragePtr table = context.getTable(database_name, table_name); - - { - auto column = ColumnUInt8::create(); - column->insert(UInt64(table->checkData())); - result = Block{{std::move(column), std::make_shared(), "result"}}; - - BlockIO res; - res.in = std::make_shared(result); - - return res; - } -} - -} // namespace DB diff --git a/dbms/src/Interpreters/InterpreterCheckQuery.h b/dbms/src/Interpreters/InterpreterCheckQuery.h deleted file mode 100644 index b0de817ab53..00000000000 --- a/dbms/src/Interpreters/InterpreterCheckQuery.h +++ /dev/null @@ -1,38 +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 - -namespace DB -{ -class Context; - -class InterpreterCheckQuery : public IInterpreter -{ -public: - InterpreterCheckQuery(const ASTPtr & query_ptr_, const Context & context_); - - BlockIO execute() override; - -private: - ASTPtr query_ptr; - - const Context & context; - Block result; -}; - -} // namespace DB diff --git a/dbms/src/Interpreters/InterpreterFactory.cpp b/dbms/src/Interpreters/InterpreterFactory.cpp index e319ca5d7ec..1007dbf8f71 100644 --- a/dbms/src/Interpreters/InterpreterFactory.cpp +++ b/dbms/src/Interpreters/InterpreterFactory.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -35,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -147,10 +145,6 @@ std::unique_ptr InterpreterFactory::get(ASTPtr & query, Context & throwIfReadOnly(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())) { bool allow_materialized = static_cast(context.getSettingsRef().insert_allow_materialized_columns); diff --git a/dbms/src/Parsers/ASTCheckQuery.h b/dbms/src/Parsers/ASTCheckQuery.h deleted file mode 100644 index 9ece682c2b0..00000000000 --- a/dbms/src/Parsers/ASTCheckQuery.h +++ /dev/null @@ -1,60 +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 -{ - -struct ASTCheckQuery : public ASTQueryWithOutput -{ - /** Get the text that identifies this element. */ - String getID() const override { return ("CheckQuery_" + database + "_" + table); }; - - ASTPtr clone() const override - { - auto res = std::make_shared(*this); - res->children.clear(); - cloneOutputOptions(*res); - return res; - } - - std::string database; - std::string table; - -protected: - void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked frame) const override - { - std::string nl_or_nothing = settings.one_line ? "" : "\n"; - - std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); - std::string nl_or_ws = settings.one_line ? " " : "\n"; - - settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "CHECK TABLE " << (settings.hilite ? hilite_none : ""); - - if (!table.empty()) - { - if (!database.empty()) - { - settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << backQuoteIfNeed(database) << (settings.hilite ? hilite_none : ""); - settings.ostr << "."; - } - settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << backQuoteIfNeed(table) << (settings.hilite ? hilite_none : ""); - } - } -}; - -} diff --git a/dbms/src/Parsers/ParserCheckQuery.cpp b/dbms/src/Parsers/ParserCheckQuery.cpp deleted file mode 100644 index ae668be50d8..00000000000 --- a/dbms/src/Parsers/ParserCheckQuery.cpp +++ /dev/null @@ -1,63 +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 - - -namespace DB -{ - -bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) -{ - ParserKeyword s_check_table("CHECK TABLE"); - ParserToken s_dot(TokenType::Dot); - - ParserIdentifier table_parser; - - ASTPtr table; - ASTPtr database; - - if (!s_check_table.ignore(pos, expected)) - return false; - if (!table_parser.parse(pos, database, expected)) - return false; - - if (s_dot.ignore(pos)) - { - if (!table_parser.parse(pos, table, expected)) - return false; - - auto query = std::make_shared(); - query->database = typeid_cast(*database).name; - query->table = typeid_cast(*table).name; - node = query; - } - else - { - table = database; - auto query = std::make_shared(); - query->table = typeid_cast(*table).name; - node = query; - } - - return true; -} - -} diff --git a/dbms/src/Parsers/ParserCheckQuery.h b/dbms/src/Parsers/ParserCheckQuery.h deleted file mode 100644 index 17d03fd3eec..00000000000 --- a/dbms/src/Parsers/ParserCheckQuery.h +++ /dev/null @@ -1,31 +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 -{ -/** Query of form - * CHECK [TABLE] [database.]table - */ -class ParserCheckQuery : public IParserBase -{ -protected: - const char * getName() const { return "ALTER query"; } - bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); -}; - -} diff --git a/dbms/src/Parsers/ParserQueryWithOutput.cpp b/dbms/src/Parsers/ParserQueryWithOutput.cpp index ca88b319bbe..7a1c36e9b84 100644 --- a/dbms/src/Parsers/ParserQueryWithOutput.cpp +++ b/dbms/src/Parsers/ParserQueryWithOutput.cpp @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include #include #include @@ -38,7 +37,6 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec ParserAlterQuery alter_p; ParserRenameQuery rename_p; ParserDropQuery drop_p; - ParserCheckQuery check_p; ASTPtr query; @@ -50,8 +48,7 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec || create_p.parse(pos, query, expected) || alter_p.parse(pos, query, expected) || rename_p.parse(pos, query, expected) - || drop_p.parse(pos, query, expected) - || check_p.parse(pos, query, expected); + || drop_p.parse(pos, query, expected); if (!parsed) return false;