From b91281455cb874d1ee856c182c62804ec0122aff Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Tue, 12 Apr 2022 15:15:21 +0300 Subject: [PATCH] clickhouse-client: properly cancel query in case of error during formatting data One example of such error is NO_ROW_DELIMITER [1]: $ clickhouse-client --stacktrace --multiquery <<<"SELECT * FROM no_length_delimiter_protobuf_00825 FORMAT ProtobufSingle SETTINGS format_schema = '$PWD/tests/queries/0_stateless/format_schemas/00825_protobuf_format_no_length_delimiter:Message'" Error on processing query: Code: 546. DB::Exception: The ProtobufSingle format can't be used to write multiple rows because this format doesn't have any row delimiter. (NO_ROW_DELIMITER), Stack trace (when copying this message, always include the lines below): ... 3. /build/build_docker/../src/Common/Exception.cpp:56: DB::Exception::Exception() 4. /build/build_docker/../src/Processors/Formats/Impl/ProtobufRowOutputFormat.cpp:43: DB::ProtobufRowOutputFormat::write() 5. /build/build_docker/../src/Processors/Formats/IRowOutputFormat.cpp:34: DB::IRowOutputFormat::consume() 6. /build/build_docker/../src/Processors/Formats/IOutputFormat.cpp:115: DB::IOutputFormat::write() 7. /build/build_docker/../src/Client/ClientBase.cpp:398: DB::ClientBase::onData() [1]: https://s3.amazonaws.com/clickhouse-test-reports/35865/b862fa7f3ede7d30b7c606c06e7fe1e273b49d32/stateless_tests__thread__actions__[3/3].html Signed-off-by: Azat Khuzhin --- src/Client/ClientBase.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 9092cb16663..7e8a7341e73 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -394,8 +394,16 @@ void ClientBase::onData(Block & block, ASTPtr parsed_query) if (need_render_progress && (stdout_is_a_tty || is_interactive) && !select_into_file) progress_indication.clearProgressOutput(); - output_format->write(materializeBlock(block)); - written_first_block = true; + try + { + output_format->write(materializeBlock(block)); + written_first_block = true; + } + catch (const Exception &) + { + /// Catch client errors like NO_ROW_DELIMITER + throw LocalFormatError(getCurrentExceptionMessage(print_stack_trace), getCurrentExceptionCode()); + } /// Received data block is immediately displayed to the user. output_format->flush();