Merging: Fixed most of problems #2260

This commit is contained in:
Alexey Milovidov 2018-06-09 19:03:07 +03:00
parent d56c199f07
commit f3d8b4e3cf
9 changed files with 84 additions and 75 deletions

View File

@ -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)

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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 = [&]()

View File

@ -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:

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,72 @@
#include <Parsers/ASTDropQuery.h>
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<ASTDropQuery>(*this);
cloneOutputOptions(*res);
return res;
}
ASTPtr ASTDropQuery::getRewrittenASTWithoutOnCluster(const std::string & new_database) const
{
auto query_ptr = clone();
auto & query = static_cast<ASTDropQuery &>(*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);
}
}

View File

@ -1,17 +1,12 @@
#pragma once
#include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOutput.h>
#include <Parsers/ASTQueryWithOnCluster.h>
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<ASTDropQuery>(*this);
cloneOutputOptions(*res);
return res;
}
ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override
{
auto query_ptr = clone();
auto & query = static_cast<ASTDropQuery &>(*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;
};
}