mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#pragma once
|
|
#include <Processors/Formats/IOutputFormat.h>
|
|
#include <Common/ConcurrentBoundedQueue.h>
|
|
#include <DataStreams/BlockStreamProfileInfo.h>
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/// LazyOutputFormat is used to retrieve ready data from executing pipeline.
|
|
/// You can periodically call `getBlock` from separate thread.
|
|
/// Used in TCPHandler.
|
|
class LazyOutputFormat : public IOutputFormat
|
|
{
|
|
|
|
public:
|
|
explicit LazyOutputFormat(const Block & header)
|
|
: IOutputFormat(header, out), queue(2), finished_processing(false) {}
|
|
|
|
String getName() const override { return "LazyOutputFormat"; }
|
|
|
|
Block getBlock(UInt64 milliseconds = 0);
|
|
Block getTotals();
|
|
Block getExtremes();
|
|
|
|
bool isFinished() { return finished_processing && queue.size() == 0; }
|
|
|
|
BlockStreamProfileInfo & getProfileInfo() { return info; }
|
|
|
|
void setRowsBeforeLimit(size_t rows_before_limit) override;
|
|
|
|
void finish()
|
|
{
|
|
finished_processing = true;
|
|
/// Clear queue in case if somebody is waiting lazy_format to push.
|
|
queue.clear();
|
|
}
|
|
|
|
protected:
|
|
void consume(Chunk chunk) override
|
|
{
|
|
if (!finished_processing)
|
|
queue.emplace(std::move(chunk));
|
|
}
|
|
|
|
void consumeTotals(Chunk chunk) override { totals = std::move(chunk); }
|
|
void consumeExtremes(Chunk chunk) override { extremes = std::move(chunk); }
|
|
|
|
void finalize() override
|
|
{
|
|
finished_processing = true;
|
|
|
|
/// In case we are waiting for result.
|
|
queue.emplace(Chunk());
|
|
}
|
|
|
|
private:
|
|
|
|
ConcurrentBoundedQueue<Chunk> queue;
|
|
Chunk totals;
|
|
Chunk extremes;
|
|
|
|
/// Is not used.
|
|
static WriteBuffer out;
|
|
|
|
BlockStreamProfileInfo info;
|
|
|
|
std::atomic<bool> finished_processing;
|
|
};
|
|
|
|
}
|