mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
|
|
/** RENAME запрос
|
|
*/
|
|
class ASTRenameQuery : public IAST
|
|
{
|
|
public:
|
|
struct Table
|
|
{
|
|
String database;
|
|
String table;
|
|
};
|
|
|
|
struct Element
|
|
{
|
|
Table from;
|
|
Table to;
|
|
};
|
|
|
|
using Elements = std::vector<Element>;
|
|
Elements elements;
|
|
|
|
ASTRenameQuery() = default;
|
|
ASTRenameQuery(const StringRange range_) : IAST(range_) {}
|
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
|
String getID() const override { return "Rename"; };
|
|
|
|
ASTPtr clone() const override { return std::make_shared<ASTRenameQuery>(*this); }
|
|
|
|
protected:
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
|
{
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "RENAME TABLE " << (settings.hilite ? hilite_none : "");
|
|
|
|
for (ASTRenameQuery::Elements::const_iterator it = elements.begin(); it != elements.end(); ++it)
|
|
{
|
|
if (it != elements.begin())
|
|
settings.ostr << ", ";
|
|
|
|
settings.ostr << (!it->from.database.empty() ? backQuoteIfNeed(it->from.database) + "." : "") << backQuoteIfNeed(it->from.table)
|
|
<< (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : "")
|
|
<< (!it->to.database.empty() ? backQuoteIfNeed(it->to.database) + "." : "") << backQuoteIfNeed(it->to.table);
|
|
}
|
|
}
|
|
};
|
|
|
|
}
|