2013-02-20 13:17:50 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
2015-06-25 17:38:54 +00:00
|
|
|
|
|
2013-09-03 20:21:28 +00:00
|
|
|
|
/** Запрос с секцией FORMAT.
|
2015-06-25 17:38:54 +00:00
|
|
|
|
*/
|
2013-09-03 20:21:28 +00:00
|
|
|
|
class ASTQueryWithOutput : public IAST
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ASTPtr format;
|
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
|
ASTQueryWithOutput() = default;
|
|
|
|
|
ASTQueryWithOutput(const StringRange range_) : IAST(range_) {}
|
2015-06-25 17:38:54 +00:00
|
|
|
|
|
|
|
|
|
/** Возвращает указатель на формат. Если типом объекта является ASTSelectQuery,
|
|
|
|
|
* то эта функция возвращает указатель на формат из последнего SELECT'а цепочки UNION ALL.
|
|
|
|
|
*/
|
|
|
|
|
virtual const IAST * getFormat() const { return format.get(); }
|
2013-09-03 20:21:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Объявляет класс-наследник ASTQueryWithOutput с реализованными методами getID и clone.
|
2015-08-06 03:26:27 +00:00
|
|
|
|
#define DEFINE_AST_QUERY_WITH_OUTPUT(Name, ID, Query) \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
class Name : public ASTQueryWithOutput \
|
|
|
|
|
{ \
|
|
|
|
|
public: \
|
|
|
|
|
Name() {} \
|
|
|
|
|
Name(StringRange range_) : ASTQueryWithOutput(range_) {} \
|
2014-12-17 15:26:24 +00:00
|
|
|
|
String getID() const override { return ID; }; \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
\
|
2014-12-17 15:26:24 +00:00
|
|
|
|
ASTPtr clone() const override \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
{ \
|
2016-06-09 04:37:21 +00:00
|
|
|
|
std::shared_ptr<Name> res = std::make_shared<Name>(*this); \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
res->children.clear(); \
|
|
|
|
|
if (format) \
|
|
|
|
|
{ \
|
|
|
|
|
res->format = format->clone(); \
|
|
|
|
|
res->children.push_back(res->format); \
|
|
|
|
|
} \
|
2016-06-09 04:37:21 +00:00
|
|
|
|
return res; \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
} \
|
2015-08-06 03:26:27 +00:00
|
|
|
|
\
|
|
|
|
|
protected: \
|
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override \
|
|
|
|
|
{ \
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << Query << (settings.hilite ? hilite_none : ""); \
|
|
|
|
|
} \
|
2013-09-03 20:21:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-02-20 13:17:50 +00:00
|
|
|
|
}
|