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-01-11 19:05:46 +00:00
|
|
|
ASTPtr out_file;
|
Fix UB for INTO OUTFILE extensions (APPEND / AND STDOUT)
MSAn report:
==38627==WARNING: MemorySanitizer: use-of-uninitialized-value
0 0x555599f5e114 in std::__1::__unique_if<DB::WriteBufferFromFile>::__unique_single std::__1::make_unique[abi:v15000]<> build_docker/./contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:714:32
1 0x555599f5e114 in DB::ClientBase::initOutputFormat() build_docker/./src/Client/ClientBase.cpp:604:21
2 0x555599f590a8 in DB::ClientBase::onData() build_docker/./src/Client/ClientBase.cpp:446:5
3 0x555599f6f36e in DB::ClientBase::receiveAndProcessPacket() build_docker/./src/Client/ClientBase.cpp:1019:17
4 0x555599f6e863 in DB::ClientBase::receiveResult() build_docker/./src/Client/ClientBase.cpp:987:18
5 0x555599f6c05b in DB::ClientBase::processOrdinaryQuery() build_docker/./src/Client/ClientBase.cpp:905:13
6 0x555599f67e05 in DB::ClientBase::processParsedSingleQuery() build_docker/./src/Client/ClientBase.cpp:1711:13
7 0x555599f86fb6 in DB::ClientBase::executeMultiQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) build_docker/./src/Client/ClientBase.cpp:1975:21
Uninitialized value was created by a heap allocation
8 0x55559bd3e038 in DB::ParserExplainQuery::parseImpl(DB::IParser::Pos&, std::__1::shared_ptr<DB::IAST>&, DB::Expected&) build_docker/./src/Parsers/ParserExplainQuery.cpp:53:26
9 0x55559bce31f4 in DB::IParserBase::parse(DB::IParser::Pos&, std::__1::shared_ptr<DB::IAST>&, DB::Expected&)::$_0::operator()() const build_docker/./src/Parsers/IParserBase.cpp:13:20
..
21 0x55559be13b5c in DB::parseQueryAndMovePosition(DB::IParser&, char const*&, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, unsigned long, unsigned long) build_docker/./src/Parsers/parseQuery.cpp:357:18
22 0x555599f5673a in DB::ClientBase::parseQuery(char const*&, char const*, bool) const build_docker/./src/Client/ClientBase.cpp:362:15
23 0x555599f84a4f in DB::ClientBase::analyzeMultiQueryText() build_docker/./src/Client/ClientBase.cpp:1821:24
24 0x555599f867b3 in DB::ClientBase::executeMultiQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) build_docker/./src/Client/ClientBase.cpp:1910:22
25 0x555599f8a2fd in DB::ClientBase::processQueryText(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) build_docker/./src/Client/ClientBase.cpp:2120:12
26 0x555599f94aee in DB::ClientBase::runNonInteractive() build_docker/./src/Client/ClientBase.cpp:2403:9
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-05-25 07:57:32 +00:00
|
|
|
bool is_into_outfile_with_stdout = false;
|
|
|
|
bool is_outfile_append = false;
|
2023-06-13 08:18:36 +00:00
|
|
|
bool is_outfile_truncate = false;
|
2013-09-03 20:21:28 +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:
|
|
|
|
/// 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;
|
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
|
|
|
}
|