2013-02-20 13:17:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2013-02-20 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-04-01 07:20:54 +00:00
|
|
|
ASTPtr out_file;
|
|
|
|
ASTPtr format;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTQueryWithOutput() = default;
|
2017-08-03 17:00:41 +00:00
|
|
|
explicit ASTQueryWithOutput(const StringRange range_) : IAST(range_) {}
|
2015-06-25 17:38:54 +00:00
|
|
|
|
2017-11-01 14:34:05 +00:00
|
|
|
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const final;
|
2017-09-17 18:49:43 +00:00
|
|
|
|
2017-01-11 19:05:46 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
/// NOTE: call this helper at the end of the clone() method of descendant class.
|
|
|
|
void cloneOutputOptions(ASTQueryWithOutput & cloned) const;
|
2017-01-11 19:05:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +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;
|
2013-09-03 20:21:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-01 14:34:05 +00:00
|
|
|
template <typename AstIDAndQueryNames>
|
|
|
|
class ASTQueryWithOutputImpl : public ASTQueryWithOutput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ASTQueryWithOutputImpl() = default;
|
|
|
|
explicit ASTQueryWithOutputImpl(StringRange range_) : ASTQueryWithOutput(range_) {}
|
|
|
|
String getID() const override { return AstIDAndQueryNames::ID; };
|
|
|
|
|
|
|
|
ASTPtr clone() const override
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTQueryWithOutputImpl<AstIDAndQueryNames>>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
cloneOutputOptions(*res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2017-12-04 20:34:27 +00:00
|
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
|
2017-11-01 14:34:05 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< AstIDAndQueryNames::Query << (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
2013-09-03 20:21:28 +00:00
|
|
|
};
|
|
|
|
|
2013-02-20 13:17:50 +00:00
|
|
|
}
|