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
|
|
|
|
|
2017-01-11 19:05:46 +00:00
|
|
|
|
/** Query with output options (supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] suffix).
|
2015-06-25 17:38:54 +00:00
|
|
|
|
*/
|
2013-09-03 20:21:28 +00:00
|
|
|
|
class ASTQueryWithOutput : public IAST
|
|
|
|
|
{
|
|
|
|
|
public:
|
2017-01-11 19:05:46 +00:00
|
|
|
|
ASTPtr out_file;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
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
|
|
|
|
|
2017-01-11 19:05:46 +00:00
|
|
|
|
protected:
|
|
|
|
|
/// NOTE: call this helper at the end of the clone() method of descendant class.
|
2017-01-19 12:02:30 +00:00
|
|
|
|
void cloneOutputOptions(ASTQueryWithOutput & cloned) const;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
|
|
|
|
|
/// Format only the query part of the AST (without output options).
|
|
|
|
|
virtual void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const = 0;
|
|
|
|
|
|
|
|
|
|
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override final;
|
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(); \
|
2017-01-11 19:05:46 +00:00
|
|
|
|
cloneOutputOptions(*res); \
|
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: \
|
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
|
|
|
|
{ \
|
|
|
|
|
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
|
|
|
|
}
|