提交 67fca7e0 编写于 作者: V Vitaly Baranov

Add support for settings 'format_schema' in an output query.

This fixes syntax error when executing 'SELECT ... FORMAT ... SETTINGS format_schema=...'
上级 0ac0557e
......@@ -56,6 +56,7 @@
#include <Parsers/formatAST.h>
#include <Parsers/parseQuery.h>
#include <Interpreters/Context.h>
#include <Interpreters/InterpreterSetQuery.h>
#include <Client/Connection.h>
#include <Common/InterruptListener.h>
#include <Functions/registerFunctions.h>
......@@ -1206,6 +1207,10 @@ private:
const auto & id = typeid_cast<const ASTIdentifier &>(*query_with_output->format);
current_format = id.name;
}
if (query_with_output->settings)
{
InterpreterSetQuery(query_with_output->settings, context).executeForCurrentContext();
}
}
if (has_vertical_output_suffix)
......
......@@ -26,6 +26,7 @@
#include <Interpreters/InterpreterFactory.h>
#include <Interpreters/ProcessList.h>
#include <Interpreters/QueryLog.h>
#include <Interpreters/InterpreterSetQuery.h>
#include <Interpreters/executeQuery.h>
#include "DNSCacheUpdater.h"
......@@ -502,6 +503,9 @@ void executeQuery(
? *getIdentifierName(ast_query_with_output->format)
: context.getDefaultFormat();
if (ast_query_with_output && ast_query_with_output->settings)
InterpreterSetQuery(ast_query_with_output->settings, context).executeForCurrentContext();
BlockOutputStreamPtr out = context.getOutputFormat(format_name, *out_buf, streams.in->getHeader());
if (auto stream = dynamic_cast<IProfilingBlockInputStream *>(streams.in.get()))
......
......@@ -15,6 +15,11 @@ void ASTQueryWithOutput::cloneOutputOptions(ASTQueryWithOutput & cloned) const
cloned.format = format->clone();
cloned.children.push_back(cloned.format);
}
if (settings)
{
cloned.settings = settings->clone();
cloned.children.push_back(cloned.settings);
}
}
void ASTQueryWithOutput::formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const
......@@ -34,6 +39,12 @@ void ASTQueryWithOutput::formatImpl(const FormatSettings & s, FormatState & stat
s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "FORMAT " << (s.hilite ? hilite_none : "");
format->formatImpl(s, state, frame);
}
if (settings)
{
s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "SETTINGS " << (s.hilite ? hilite_none : "");
settings->formatImpl(s, state, frame);
}
}
bool ASTQueryWithOutput::resetOutputASTIfExist(IAST & ast)
......@@ -42,6 +53,7 @@ bool ASTQueryWithOutput::resetOutputASTIfExist(IAST & ast)
{
ast_with_output->format.reset();
ast_with_output->out_file.reset();
ast_with_output->settings.reset();
return true;
}
......
......@@ -6,13 +6,15 @@
namespace DB
{
/** Query with output options (supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] suffix).
/** Query with output options
* (supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] [SETTINGS key1 = value1, key2 = value2, ...] suffix).
*/
class ASTQueryWithOutput : public IAST
{
public:
ASTPtr out_file;
ASTPtr format;
ASTPtr settings;
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const final;
......
......@@ -11,6 +11,7 @@
#include <Parsers/ParserDropQuery.h>
#include <Parsers/ParserKillQueryQuery.h>
#include <Parsers/ParserOptimizeQuery.h>
#include <Parsers/ParserSetQuery.h>
#include <Parsers/ASTExplainQuery.h>
......@@ -81,6 +82,16 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
query_with_output.children.push_back(query_with_output.format);
}
// SETTINGS key1 = value1, key2 = value2, ...
ParserKeyword s_settings("SETTINGS");
if (s_settings.ignore(pos, expected))
{
ParserSetQuery parser_settings(true);
if (!parser_settings.parse(pos, query_with_output.settings, expected))
return false;
query_with_output.children.push_back(query_with_output.settings);
}
if (explain_ast)
{
node = std::make_shared<ASTExplainQuery>();
......
......@@ -7,7 +7,7 @@
namespace DB
{
/// Parse queries supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] suffix.
/// Parse queries supporting [INTO OUTFILE 'file_name'] [FORMAT format_name] [SETTINGS key1 = value1, key2 = value2, ...] suffix.
class ParserQueryWithOutput : public IParserBase
{
public:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册