Merge pull request #7606 from amosbird/nullformat

Better Null format for tcp handler.
This commit is contained in:
alexey-milovidov 2019-11-04 14:27:27 +03:00 committed by GitHub
commit 782e2f6c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -530,6 +530,7 @@ void TCPHandler::processOrdinaryQuery()
sendLogs(); sendLogs();
} }
if (!block || !state.io.null_format)
sendData(block); sendData(block);
if (!block) if (!block)
break; break;

View File

@ -33,6 +33,9 @@ struct BlockIO
std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback; std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback;
std::function<void()> exception_callback; std::function<void()> exception_callback;
/// When it is true, don't bother sending any non-empty blocks to the out stream
bool null_format = false;
/// Call these functions if you want to log the request. /// Call these functions if you want to log the request.
void onFinish() void onFinish()
{ {

View File

@ -563,9 +563,18 @@ BlockIO executeQuery(
bool may_have_embedded_data, bool may_have_embedded_data,
bool allow_processors) bool allow_processors)
{ {
ASTPtr ast;
BlockIO streams; BlockIO streams;
std::tie(std::ignore, streams) = executeQueryImpl(query.data(), query.data() + query.size(), context, std::tie(ast, streams) = executeQueryImpl(query.data(), query.data() + query.size(), context,
internal, stage, !may_have_embedded_data, nullptr, allow_processors); internal, stage, !may_have_embedded_data, nullptr, allow_processors);
if (streams.in)
{
const auto * ast_query_with_output = dynamic_cast<const ASTQueryWithOutput *>(ast.get());
String format_name = ast_query_with_output && (ast_query_with_output->format != nullptr)
? getIdentifierName(ast_query_with_output->format) : context.getDefaultFormat();
if (format_name == "Null")
streams.null_format = true;
}
return streams; return streams;
} }