ClickHouse/src/Parsers/toOneLineQuery.cpp
Azat Khuzhin c29768325c Print query in one line on fatal errors
executeQuery() logging query without new lines in SQL, and it is useful,
since you can grep and see the whole query (usually).

So let's use the same in fatal error handler to make CI reports more
informative.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-06-03 18:55:53 +03:00

35 lines
738 B
C++

#include <Parsers/toOneLineQuery.h>
#include <Parsers/Lexer.h>
namespace DB
{
String toOneLineQuery(const String & query)
{
String res;
const char * begin = query.data();
const char * end = begin + query.size();
Lexer lexer(begin, end);
Token token = lexer.nextToken();
for (; !token.isEnd(); token = lexer.nextToken())
{
if (token.type == TokenType::Whitespace)
{
res += ' ';
}
else if (token.type == TokenType::Comment)
{
res.append(token.begin, token.end);
if (token.end < end && *token.end == '\n')
res += '\n';
}
else
res.append(token.begin, token.end);
}
return res;
}
}