ClickHouse/src/Parsers/ASTQueryWithOutput.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/IAST.h>
2020-11-09 16:05:40 +00:00
#include <IO/Operators.h>
#include "Parsers/IAST_fwd.h"
namespace DB
{
2015-06-25 17:38:54 +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
*/
class ASTQueryWithOutput : public IAST
{
public:
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;
bool is_outfile_truncate = false;
ASTPtr format;
2019-01-24 19:22:26 +00:00
ASTPtr settings_ast;
ASTPtr compression;
2022-07-06 14:15:24 +00:00
ASTPtr compression_level;
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const final;
/// Remove 'FORMAT <fmt> and INTO OUTFILE <file>' if exists
static bool resetOutputASTIfExist(IAST & ast);
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;
};
2018-02-25 06:34:20 +00:00
/** Helper template for simple queries like SHOW PROCESSLIST.
*/
template <typename ASTIDAndQueryNames>
class ASTQueryWithOutputImpl : public ASTQueryWithOutput
{
public:
String getID(char) const override { return ASTIDAndQueryNames::ID; }
ASTPtr clone() const override
{
2018-02-25 06:34:20 +00:00
auto res = std::make_shared<ASTQueryWithOutputImpl<ASTIDAndQueryNames>>(*this);
res->children.clear();
cloneOutputOptions(*res);
return res;
}
protected:
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "")
2018-02-26 03:40:20 +00:00
<< ASTIDAndQueryNames::Query << (settings.hilite ? hilite_none : "");
}
};
}