From f3d8b4e3cfddae9adca9ece589237a6316ba41a6 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 9 Jun 2018 19:03:07 +0300 Subject: [PATCH] Merging: Fixed most of problems #2260 --- .../ClusterProxy/DescribeStreamFactory.cpp | 2 +- .../ClusterProxy/DescribeStreamFactory.h | 2 +- .../ClusterProxy/IStreamFactory.h | 2 +- .../ClusterProxy/SelectStreamFactory.cpp | 2 +- .../ClusterProxy/SelectStreamFactory.h | 2 +- .../ClusterProxy/executeQuery.cpp | 2 +- .../src/Interpreters/InterpreterDropQuery.cpp | 1 + dbms/src/Parsers/ASTDropQuery.cpp | 72 ++++++++++++++++++ dbms/src/Parsers/ASTDropQuery.h | 74 ++----------------- 9 files changed, 84 insertions(+), 75 deletions(-) create mode 100644 dbms/src/Parsers/ASTDropQuery.cpp diff --git a/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.cpp b/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.cpp index 81a15720899..2638399f8ff 100644 --- a/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.cpp +++ b/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.cpp @@ -29,7 +29,7 @@ namespace ClusterProxy void DescribeStreamFactory::createForShard( const Cluster::ShardInfo & shard_info, const String & query, const ASTPtr & query_ast, - const ThrottlerPtr & throttler, Context & context, + const Context & context, const ThrottlerPtr & throttler, BlockInputStreams & res) { for (const Cluster::Address & local_address : shard_info.local_addresses) diff --git a/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.h b/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.h index 7e3cd0db138..05befc59305 100644 --- a/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.h +++ b/dbms/src/Interpreters/ClusterProxy/DescribeStreamFactory.h @@ -14,7 +14,7 @@ public: void createForShard( const Cluster::ShardInfo & shard_info, const String & query, const ASTPtr & query_ast, - const ThrottlerPtr & throttler, Context & context, + const Context & context, const ThrottlerPtr & throttler, BlockInputStreams & res) override; }; diff --git a/dbms/src/Interpreters/ClusterProxy/IStreamFactory.h b/dbms/src/Interpreters/ClusterProxy/IStreamFactory.h index 15d840028ae..beceaaecce2 100644 --- a/dbms/src/Interpreters/ClusterProxy/IStreamFactory.h +++ b/dbms/src/Interpreters/ClusterProxy/IStreamFactory.h @@ -26,7 +26,7 @@ public: virtual void createForShard( const Cluster::ShardInfo & shard_info, const String & query, const ASTPtr & query_ast, - const ThrottlerPtr & throttler, Context & context, + const Context & context, const ThrottlerPtr & throttler, BlockInputStreams & res) = 0; }; diff --git a/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp b/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp index 6ad7e407b85..24060eedcd7 100644 --- a/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp +++ b/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.cpp @@ -59,7 +59,7 @@ BlockInputStreamPtr createLocalStream(const ASTPtr & query_ast, const Context & void SelectStreamFactory::createForShard( const Cluster::ShardInfo & shard_info, const String & query, const ASTPtr & query_ast, - const ThrottlerPtr & throttler, Context & context, + const Context & context, const ThrottlerPtr & throttler, BlockInputStreams & res) { auto emplace_local_stream = [&]() diff --git a/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.h b/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.h index 2d3666f2874..5325e5d463c 100644 --- a/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.h +++ b/dbms/src/Interpreters/ClusterProxy/SelectStreamFactory.h @@ -22,7 +22,7 @@ public: void createForShard( const Cluster::ShardInfo & shard_info, const String & query, const ASTPtr & query_ast, - const ThrottlerPtr & throttler, Context & context, + const Context & context, const ThrottlerPtr & throttler, BlockInputStreams & res) override; private: diff --git a/dbms/src/Interpreters/ClusterProxy/executeQuery.cpp b/dbms/src/Interpreters/ClusterProxy/executeQuery.cpp index aeb02bc9262..27b7d8338af 100644 --- a/dbms/src/Interpreters/ClusterProxy/executeQuery.cpp +++ b/dbms/src/Interpreters/ClusterProxy/executeQuery.cpp @@ -57,7 +57,7 @@ BlockInputStreams executeQuery( throttler = user_level_throttler; for (const auto & shard_info : cluster->getShardsInfo()) - stream_factory.createForShard(shard_info, query, query_ast, throttler, new_context, res); + stream_factory.createForShard(shard_info, query, query_ast, new_context, throttler, res); return res; } diff --git a/dbms/src/Interpreters/InterpreterDropQuery.cpp b/dbms/src/Interpreters/InterpreterDropQuery.cpp index f13b9693e92..cdb107a13ad 100644 --- a/dbms/src/Interpreters/InterpreterDropQuery.cpp +++ b/dbms/src/Interpreters/InterpreterDropQuery.cpp @@ -20,6 +20,7 @@ namespace ErrorCodes extern const int UNKNOWN_DATABASE; extern const int READONLY; extern const int LOGICAL_ERROR; + extern const int SYNTAX_ERROR; extern const int UNKNOWN_TABLE; } diff --git a/dbms/src/Parsers/ASTDropQuery.cpp b/dbms/src/Parsers/ASTDropQuery.cpp new file mode 100644 index 00000000000..dff25e7023e --- /dev/null +++ b/dbms/src/Parsers/ASTDropQuery.cpp @@ -0,0 +1,72 @@ +#include + + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int SYNTAX_ERROR; +} + + +String ASTDropQuery::getID() const +{ + if (kind == ASTDropQuery::Kind::Drop) + return "DropQuery_" + database + "_" + table; + else if (kind == ASTDropQuery::Kind::Detach) + return "DetachQuery_" + database + "_" + table; + else if (kind == ASTDropQuery::Kind::Truncate) + return "TruncateQuery_" + database + "_" + table; + else + throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); +} + +ASTPtr ASTDropQuery::clone() const +{ + auto res = std::make_shared(*this); + cloneOutputOptions(*res); + return res; +} + +ASTPtr ASTDropQuery::getRewrittenASTWithoutOnCluster(const std::string & new_database) const +{ + auto query_ptr = clone(); + auto & query = static_cast(*query_ptr); + + query.cluster.clear(); + if (query.database.empty()) + query.database = new_database; + + return query_ptr; +} + +void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const +{ + settings.ostr << (settings.hilite ? hilite_keyword : ""); + if (kind == ASTDropQuery::Kind::Drop) + settings.ostr << "DROP "; + else if (kind == ASTDropQuery::Kind::Detach) + settings.ostr << "DETACH "; + else if (kind == ASTDropQuery::Kind::Truncate) + settings.ostr << "TRUNCATE "; + else + throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); + + settings.ostr << ((table.empty() && !database.empty()) ? "DATABASE " : "TABLE "); + + if (if_exists) + settings.ostr << "IF EXISTS "; + + settings.ostr << (settings.hilite ? hilite_none : ""); + + if (table.empty() && !database.empty()) + settings.ostr << backQuoteIfNeed(database); + else + settings.ostr << (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table); + + formatOnCluster(settings); +} + +} + diff --git a/dbms/src/Parsers/ASTDropQuery.h b/dbms/src/Parsers/ASTDropQuery.h index 67da3346964..64d30b9453f 100644 --- a/dbms/src/Parsers/ASTDropQuery.h +++ b/dbms/src/Parsers/ASTDropQuery.h @@ -1,17 +1,12 @@ #pragma once -#include #include #include + namespace DB { -namespace ErrorCodes -{ - extern const int SYNTAX_ERROR; -} - /** DROP query */ class ASTDropQuery : public ASTQueryWithOutput, public ASTQueryWithOnCluster @@ -31,72 +26,13 @@ public: String table; /** Get the text that identifies this element. */ - String getID() const override - { - if (kind == ASTDropQuery::Kind::Drop) - return "DropQuery_" + database + "_" + table; - else if (kind == ASTDropQuery::Kind::Detach) - return "DetachQuery_" + database + "_" + table; - else if (kind == ASTDropQuery::Kind::Truncate) - return "TruncateQuery_" + database + "_" + table; - else - throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); - } + String getID() const override; + ASTPtr clone() const override; - ASTPtr clone() const override - { - auto res = std::make_shared(*this); - cloneOutputOptions(*res); - return res; - } - - ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override - { - auto query_ptr = clone(); - auto & query = static_cast(*query_ptr); - - query.cluster.clear(); - if (query.database.empty()) - query.database = new_database; - - return query_ptr; - } + ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override; protected: - void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override - { - if (table.empty() && !database.empty()) - { - settings.ostr << (settings.hilite ? hilite_keyword : ""); - if (kind == ASTDropQuery::Kind::Drop) - settings.ostr << "DROP DATABASE "; - else if (kind == ASTDropQuery::Kind::Detach) - settings.ostr << "DETACH DATABASE "; - else if (kind == ASTDropQuery::Kind::Truncate) - settings.ostr << "TRUNCATE DATABASE "; - else - throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); - - settings.ostr << (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "") << backQuoteIfNeed(database); - formatOnCluster(settings); - } - else - { - settings.ostr << (settings.hilite ? hilite_keyword : ""); - if (kind == ASTDropQuery::Kind::Drop) - settings.ostr << "DROP TABLE "; - else if (kind == ASTDropQuery::Kind::Detach) - settings.ostr << "DETACH TABLE "; - else if (kind == ASTDropQuery::Kind::Truncate) - settings.ostr << "TRUNCATE TABLE "; - else - throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); - - settings.ostr << (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "") - << (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table); - formatOnCluster(settings); - } - } + void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override; }; }