ClickHouse/src/Parsers/ASTDropQuery.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.4 KiB
C++
Raw Normal View History

2018-06-09 16:03:07 +00:00
#include <Parsers/ASTDropQuery.h>
#include <Common/quoteString.h>
2020-11-09 16:05:40 +00:00
#include <IO/Operators.h>
2018-06-09 16:03:07 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int SYNTAX_ERROR;
}
String ASTDropQuery::getID(char delim) const
2018-06-09 16:03:07 +00:00
{
if (kind == ASTDropQuery::Kind::Drop)
return "DropQuery" + (delim + getDatabase()) + delim + getTable();
2018-06-09 16:03:07 +00:00
else if (kind == ASTDropQuery::Kind::Detach)
return "DetachQuery" + (delim + getDatabase()) + delim + getTable();
2018-06-09 16:03:07 +00:00
else if (kind == ASTDropQuery::Kind::Truncate)
return "TruncateQuery" + (delim + getDatabase()) + delim + getTable();
2018-06-09 16:03:07 +00:00
else
throw Exception(ErrorCodes::SYNTAX_ERROR, "Not supported kind of drop query.");
2018-06-09 16:03:07 +00:00
}
ASTPtr ASTDropQuery::clone() const
{
auto res = std::make_shared<ASTDropQuery>(*this);
cloneOutputOptions(*res);
cloneTableOptions(*res);
2018-06-09 16:03:07 +00:00
return res;
}
2024-02-19 07:15:28 +00:00
void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
2018-06-09 16:03:07 +00:00
{
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(ErrorCodes::SYNTAX_ERROR, "Not supported kind of drop query.");
2018-06-09 16:03:07 +00:00
if (temporary)
settings.ostr << "TEMPORARY ";
2021-11-11 13:28:18 +00:00
if (!table && database)
2019-10-08 11:10:29 +00:00
settings.ostr << "DATABASE ";
2020-03-23 22:28:30 +00:00
else if (is_dictionary)
2019-10-08 11:10:29 +00:00
settings.ostr << "DICTIONARY ";
2020-03-23 22:28:30 +00:00
else if (is_view)
settings.ostr << "VIEW ";
else
settings.ostr << "TABLE ";
2018-06-09 16:03:07 +00:00
if (if_exists)
settings.ostr << "IF EXISTS ";
2023-09-21 13:20:18 +00:00
if (if_empty)
settings.ostr << "IF EMPTY ";
2018-06-09 16:03:07 +00:00
settings.ostr << (settings.hilite ? hilite_none : "");
2021-11-11 13:28:18 +00:00
if (!table && database)
2024-02-19 07:15:28 +00:00
{
database->formatImpl(settings, state, frame);
}
2018-06-09 16:03:07 +00:00
else
2024-02-19 07:15:28 +00:00
{
if (database)
{
database->formatImpl(settings, state, frame);
settings.ostr << '.';
}
2024-03-08 20:27:56 +00:00
chassert(table);
2024-02-19 07:15:28 +00:00
table->formatImpl(settings, state, frame);
}
2018-06-09 16:03:07 +00:00
formatOnCluster(settings);
2020-03-20 00:07:52 +00:00
2020-11-30 17:52:32 +00:00
if (permanently)
settings.ostr << " PERMANENTLY";
2022-06-23 07:59:13 +00:00
if (sync)
settings.ostr << (settings.hilite ? hilite_keyword : "") << " SYNC" << (settings.hilite ? hilite_none : "");
2018-06-09 16:03:07 +00:00
}
}