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)
        {
            auto pipe = getSourceFromFromASTInsertQuery(ast, &istr, streams.out->getHeader(), context, nullptr);
            pipeline.init(std::move(pipe));
            pipeline.resize(1);
            pipeline.setSinks([&](const Block &, Pipe::StreamType)
            {
                return std::make_shared<SinkToOutputStream>(streams.out);
            });
            auto executor = pipeline.execute();
            executor->execute(pipeline.getNumThreads());
        }
        else if (streams.in)
        {
            const auto * ast_query_with_output = dynamic_cast<const ASTQueryWithOutput *>(ast.get());
            WriteBuffer * out_buf = &ostr;
            std::unique_ptr<WriteBuffer> compressed_buffer;
            if (ast_query_with_output && ast_query_with_output->out_file)
            {
                if (!allow_into_outfile)
                    throw Exception("INTO OUTFILE is not allowed", ErrorCodes::INTO_OUTFILE_NOT_ALLOWED);
                const auto & out_file = ast_query_with_output->out_file->as<ASTLiteral &>().value.safeGet<std::string>();
                compressed_buffer = wrapWriteBufferWithCompressionMethod(
                    std::make_unique<WriteBufferFromFile>(out_file, DBMS_DEFAULT_BUFFER_SIZE, O_WRONLY | O_EXCL | O_CREAT),
                    chooseCompressionMethod(out_file, ""),
                     3
                );
            }