ClickHouse/dbms/src/Parsers/ASTDropQuery.h

68 lines
2.0 KiB
C++
Raw Normal View History

2011-11-05 23:31:19 +00:00
#pragma once
#include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOutput.h>
2017-04-21 12:39:28 +00:00
#include <Parsers/ASTQueryWithOnCluster.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
*/
class ASTDropQuery : public ASTQueryWithOutput, public ASTQueryWithOnCluster
2011-11-05 23:31:19 +00:00
{
public:
2017-05-27 17:27:16 +00:00
bool detach{false}; /// DETACH query, not DROP.
bool if_exists{false};
bool temporary{false};
String database;
String table;
2011-11-05 23:31:19 +00:00
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
String getID() const override { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; }
2011-12-12 06:15:34 +00:00
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;
}
protected:
2017-12-01 18:36:55 +00:00
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) 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);
formatOnCluster(settings);
}
else
{
settings.ostr << (settings.hilite ? hilite_keyword : "")
<< (detach ? "DETACH TABLE " : "DROP TABLE ")
<< (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "")
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
formatOnCluster(settings);
}
}
2011-11-05 23:31:19 +00:00
};
}