With a large volume of queries per second logging all queries gets expensive, it would be nice to be able to log only a configurable fraction of the queries, selected at random.
{
    try
    {
        if (streams.out)
            throw Exception(ErrorCodes::LOGICAL_ERROR, "Query stream requires input, but no input buffer provided, it's a bug");
        if (streams.in)
            throw Exception(ErrorCodes::LOGICAL_ERROR, "Query stream requires output, but no output buffer provided, it's a bug");
        if (!streams.pipeline.initialized())
            return;
        if (!streams.pipeline.isCompleted())
            throw Exception(ErrorCodes::LOGICAL_ERROR, "Query pipeline requires output, but no output buffer provided, it's a bug");
        streams.pipeline.setProgressCallback(context->getProgressCallback());
        auto executor = streams.pipeline.execute();
        executor->execute(streams.pipeline.getNumThreads());
    }
    catch (...)
    {
        streams.onException();
        throw;
    }
    streams.onFinish();
}
}