2013-02-21 10:02:33 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
#include <DB/Parsers/ASTQueryWithOutput.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
|
/** Запрос с указанием названия таблицы и, возможно, БД и секцией FORMAT.
|
|
|
|
|
*/
|
|
|
|
|
class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
String database;
|
|
|
|
|
String table;
|
|
|
|
|
|
|
|
|
|
ASTQueryWithTableAndOutput() = default;
|
|
|
|
|
ASTQueryWithTableAndOutput(const StringRange range_) : ASTQueryWithOutput(range_) {}
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void formatHelper(const FormatSettings & settings, FormatState & state, FormatStateStacked frame, const char * name) const
|
|
|
|
|
{
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "")
|
|
|
|
|
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
|
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
};
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
|
/// Объявляет класс-наследник ASTQueryWithTableAndOutput с реализованными методами getID и clone.
|
2015-08-06 03:26:27 +00:00
|
|
|
|
#define DEFINE_AST_QUERY_WITH_TABLE_AND_OUTPUT(Name, ID, Query) \
|
2013-02-21 10:02:33 +00:00
|
|
|
|
class Name : public ASTQueryWithTableAndOutput \
|
|
|
|
|
{ \
|
2015-08-06 03:26:27 +00:00
|
|
|
|
public: \
|
2014-12-17 15:26:24 +00:00
|
|
|
|
Name() = default; \
|
|
|
|
|
Name(const StringRange range_) : ASTQueryWithTableAndOutput(range_) {} \
|
|
|
|
|
String getID() const override { return ID"_" + database + "_" + table; }; \
|
2015-05-03 09:13:08 +00:00
|
|
|
|
\
|
2014-12-17 15:26:24 +00:00
|
|
|
|
ASTPtr clone() const override \
|
2013-02-21 10:02:33 +00:00
|
|
|
|
{ \
|
2016-06-09 04:37:21 +00:00
|
|
|
|
std::shared_ptr<Name> res = std::make_shared<Name>(*this); \
|
2013-02-21 10:02:33 +00:00
|
|
|
|
res->children.clear(); \
|
2017-01-11 19:05:46 +00:00
|
|
|
|
cloneOutputOptions(*res); \
|
2016-06-09 04:37:21 +00:00
|
|
|
|
return res; \
|
2013-02-21 10:02:33 +00:00
|
|
|
|
} \
|
2015-08-06 03:26:27 +00:00
|
|
|
|
\
|
|
|
|
|
protected: \
|
2017-01-11 19:05:46 +00:00
|
|
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override \
|
2015-08-06 03:26:27 +00:00
|
|
|
|
{ \
|
|
|
|
|
formatHelper(settings, state, frame, Query); \
|
|
|
|
|
} \
|
2013-02-21 10:02:33 +00:00
|
|
|
|
};
|
|
|
|
|
}
|