2013-02-20 13:17:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2021-08-03 11:33:52 +00:00
|
|
|
#include "Parsers/IAST_fwd.h"
|
2013-02-20 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2015-06-25 17:38:54 +00:00
|
|
|
|
2019-01-23 19:23:37 +00:00
|
|
|
/** Query with output options
|
|
|
|
* (supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] [SETTINGS key1 = value1, key2 = value2, ...] 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;
|
2022-07-05 18:03:51 +00:00
|
|
|
bool is_stdout_enabled;
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr format;
|
2019-01-24 19:22:26 +00:00
|
|
|
ASTPtr settings_ast;
|
2021-08-03 11:33:52 +00:00
|
|
|
ASTPtr compression;
|
2022-07-06 14:15:24 +00:00
|
|
|
ASTPtr compression_level;
|
2013-09-03 20:21:28 +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
|
|
|
|
2018-02-12 18:41:53 +00:00
|
|
|
/// Remove 'FORMAT <fmt> and INTO OUTFILE <file>' if exists
|
|
|
|
static bool resetOutputASTIfExist(IAST & ast);
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-25 06:34:20 +00:00
|
|
|
/** Helper template for simple queries like SHOW PROCESSLIST.
|
|
|
|
*/
|
|
|
|
template <typename ASTIDAndQueryNames>
|
2017-11-01 14:34:05 +00:00
|
|
|
class ASTQueryWithOutputImpl : public ASTQueryWithOutput
|
|
|
|
{
|
|
|
|
public:
|
2018-12-07 12:34:40 +00:00
|
|
|
String getID(char) const override { return ASTIDAndQueryNames::ID; }
|
2017-11-01 14:34:05 +00:00
|
|
|
|
|
|
|
ASTPtr clone() const override
|
|
|
|
{
|
2018-02-25 06:34:20 +00:00
|
|
|
auto res = std::make_shared<ASTQueryWithOutputImpl<ASTIDAndQueryNames>>(*this);
|
2017-11-01 14:34:05 +00:00
|
|
|
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 : "")
|
2018-02-26 03:40:20 +00:00
|
|
|
<< ASTIDAndQueryNames::Query << (settings.hilite ? hilite_none : "");
|
2017-11-01 14:34:05 +00:00
|
|
|
}
|
2013-09-03 20:21:28 +00:00
|
|
|
};
|
|
|
|
|
2013-02-20 13:17:50 +00:00
|
|
|
}
|