Flush output for interactive applications

This commit is contained in:
Alexey Milovidov 2020-04-19 22:02:36 +03:00
parent cf6bbaeb97
commit 5262512f0c
3 changed files with 9 additions and 0 deletions

View File

@ -721,6 +721,7 @@ void executeQuery(
}); });
auto out = context.getOutputFormatProcessor(format_name, *out_buf, pipeline.getHeader()); auto out = context.getOutputFormatProcessor(format_name, *out_buf, pipeline.getHeader());
out->setAutoFlush();
/// Save previous progress callback if any. TODO Do it more conveniently. /// Save previous progress callback if any. TODO Do it more conveniently.
auto previous_progress_callback = context.getProgressCallback(); auto previous_progress_callback = context.getProgressCallback();

View File

@ -69,6 +69,9 @@ void IOutputFormat::work()
break; break;
} }
if (auto_flush)
flush();
has_input = false; has_input = false;
} }

View File

@ -34,6 +34,9 @@ protected:
bool finished = false; bool finished = false;
bool finalized = false; bool finalized = false;
/// Flush data on each consumed chunk. This is intented for interactive applications to output data as soon as it's ready.
bool auto_flush = false;
RowsBeforeLimitCounterPtr rows_before_limit_counter; RowsBeforeLimitCounterPtr rows_before_limit_counter;
virtual void consume(Chunk) = 0; virtual void consume(Chunk) = 0;
@ -50,6 +53,8 @@ public:
/// Flush output buffers if any. /// Flush output buffers if any.
virtual void flush(); virtual void flush();
void setAutoFlush() { auto_flush = true; }
/// Value for rows_before_limit_at_least field. /// Value for rows_before_limit_at_least field.
virtual void setRowsBeforeLimit(size_t /*rows_before_limit*/) {} virtual void setRowsBeforeLimit(size_t /*rows_before_limit*/) {}