2011-11-05 23:31:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2017-04-13 16:12:56 +00:00
|
|
|
#include <Parsers/ASTDDLQueryWithOnCluster.h>
|
2011-11-05 23:31:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** DROP query
|
2011-11-05 23:31:19 +00:00
|
|
|
*/
|
2017-04-13 16:12:56 +00:00
|
|
|
class ASTDropQuery : public IAST, public ASTDDLQueryWithOnCluster
|
2011-11-05 23:31:19 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-27 17:27:16 +00:00
|
|
|
bool detach{false}; /// DETACH query, not DROP.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool if_exists{false};
|
|
|
|
String database;
|
|
|
|
String table;
|
2011-11-05 23:31:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTDropQuery() = default;
|
|
|
|
ASTDropQuery(const StringRange range_) : IAST(range_) {}
|
2017-03-31 16:00:30 +00:00
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Get the text that identifies this element. */
|
2017-04-01 07:20:54 +00:00
|
|
|
String getID() const override { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; };
|
2011-12-12 06:15:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr clone() const override { return std::make_shared<ASTDropQuery>(*this); }
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2017-04-13 16:12:56 +00:00
|
|
|
ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override
|
|
|
|
{
|
|
|
|
auto query_ptr = clone();
|
|
|
|
ASTDropQuery & query = static_cast<ASTDropQuery &>(*query_ptr);
|
|
|
|
|
|
|
|
query.cluster.clear();
|
|
|
|
if (query.database.empty())
|
|
|
|
query.database = new_database;
|
|
|
|
|
|
|
|
return query_ptr;
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
|
|
|
{
|
|
|
|
if (table.empty() && !database.empty())
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< (detach ? "DETACH DATABASE " : "DROP DATABASE ")
|
|
|
|
<< (if_exists ? "IF EXISTS " : "")
|
|
|
|
<< (settings.hilite ? hilite_none : "")
|
|
|
|
<< backQuoteIfNeed(database);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< (detach ? "DETACH TABLE " : "DROP TABLE ")
|
|
|
|
<< (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "")
|
2017-04-13 16:12:56 +00:00
|
|
|
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table)
|
|
|
|
<< (!cluster.empty() ? " ON CLUSTER " + backQuoteIfNeed(cluster) + " " : "");
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2011-11-05 23:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|