clickhouse-client: echo queries only after "{ echo }" hint

Before this patch clickhouse-client interprets the whole queries and if
"{ echo }" found, it starts echoing queries, but this will make it
impossible to skip some of lines.
This commit is contained in:
Azat Khuzhin 2021-06-01 08:54:27 +03:00
parent ddbdf68814
commit 1c595c127f
3 changed files with 24 additions and 15 deletions

View File

@ -965,13 +965,10 @@ private:
TestHint test_hint(test_mode, all_queries_text);
if (test_hint.clientError() || test_hint.serverError())
processTextAsSingleQuery("SET send_logs_level = 'fatal'");
// Echo all queries if asked; makes for a more readable reference
// file.
if (test_hint.echoQueries())
echo_queries = true;
}
bool echo_queries_ = echo_queries;
/// Several queries separated by ';'.
/// INSERT data is ended by the end of line, not ';'.
/// An exception is VALUES format where we also support semicolon in
@ -1104,9 +1101,21 @@ private:
continue;
}
// Now we know for sure where the query ends.
// Look for the hint in the text of query + insert data + trailing
// comments,
// e.g. insert into t format CSV 'a' -- { serverError 123 }.
// Use the updated query boundaries we just calculated.
TestHint test_hint(test_mode, std::string(this_query_begin, this_query_end - this_query_begin));
// Echo all queries if asked; makes for a more readable reference
// file.
if (test_hint.echoQueries())
echo_queries_ = true;
try
{
processParsedSingleQuery();
processParsedSingleQuery(echo_queries_);
}
catch (...)
{
@ -1128,13 +1137,6 @@ private:
adjustQueryEnd(this_query_end, all_queries_end, context->getSettingsRef().max_parser_depth);
}
// Now we know for sure where the query ends.
// Look for the hint in the text of query + insert data + trailing
// comments,
// e.g. insert into t format CSV 'a' -- { serverError 123 }.
// Use the updated query boundaries we just calculated.
TestHint test_hint(test_mode, std::string(this_query_begin, this_query_end - this_query_begin));
// Check whether the error (or its absence) matches the test hints
// (or their absence).
bool error_matches_hint = true;
@ -1545,14 +1547,14 @@ private:
// 'query_to_send' -- the query text that is sent to server,
// 'full_query' -- for INSERT queries, contains the query and the data that
// follow it. Its memory is referenced by ASTInsertQuery::begin, end.
void processParsedSingleQuery()
void processParsedSingleQuery(std::optional<bool> echo_queries_ = {})
{
resetOutput();
client_exception.reset();
server_exception.reset();
have_error = false;
if (echo_queries)
if (echo_queries_.value_or(echo_queries))
{
writeString(full_query, std_out);
writeChar('\n', std_out);

View File

@ -0,0 +1,4 @@
1
-- { echo }
select 1;
1

View File

@ -0,0 +1,3 @@
select 1;
-- { echo }
select 1;