Set query id in case of exceptions during query execution

This commit is contained in:
Frank Chen 2023-03-21 14:10:01 +08:00
parent a04b38db90
commit 91a34fa627

View File

@ -1273,18 +1273,24 @@ void executeQuery(
end = begin + parse_buf.size();
}
ASTPtr ast;
BlockIO streams;
std::tie(ast, streams) = executeQueryImpl(begin, end, context, false, QueryProcessingStage::Complete, &istr);
auto & pipeline = streams.pipeline;
QueryResultDetails result_details
{
.query_id = context->getClientInfo().current_query_id,
.timezone = DateLUT::instance().getTimeZone(),
};
// Set the result details in case of any exception raised during query execution
SCOPE_EXIT({
if (set_result_details)
set_result_details(result_details);
});
ASTPtr ast;
BlockIO streams;
std::tie(ast, streams) = executeQueryImpl(begin, end, context, false, QueryProcessingStage::Complete, &istr);
auto & pipeline = streams.pipeline;
std::unique_ptr<WriteBuffer> compressed_buffer;
try
{
@ -1353,9 +1359,13 @@ void executeQuery(
pipeline.setProgressCallback(context->getProgressCallback());
}
if (set_result_details)
if (set_result_details) {
set_result_details(result_details);
// Clear the callback so that result details won't be set twice in case of any exception raised after this point
set_result_details = nullptr;
}
if (pipeline.initialized())
{
CompletedPipelineExecutor executor(pipeline);