ClickHouse/dbms/include/DB/Parsers/ASTQueryWithOutput.h

56 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <DB/Parsers/IAST.h>
namespace DB
{
2015-06-25 17:38:54 +00:00
/** Query with output options (supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] suffix).
2015-06-25 17:38:54 +00:00
*/
class ASTQueryWithOutput : public IAST
{
public:
ASTPtr out_file;
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
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;
/// 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;
};
/// Объявляет класс-наследник ASTQueryWithOutput с реализованными методами getID и clone.
#define DEFINE_AST_QUERY_WITH_OUTPUT(Name, ID, Query) \
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; }; \
\
2014-12-17 15:26:24 +00:00
ASTPtr clone() const override \
{ \
2016-06-09 04:37:21 +00:00
std::shared_ptr<Name> res = std::make_shared<Name>(*this); \
res->children.clear(); \
cloneOutputOptions(*res); \
2016-06-09 04:37:21 +00:00
return res; \
} \
\
protected: \
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override \
{ \
settings.ostr << (settings.hilite ? hilite_keyword : "") << Query << (settings.hilite ? hilite_none : ""); \
} \
};
}