ClickHouse/dbms/src/Processors/Formats/LazyOutputFormat.h

55 lines
1.2 KiB
C++
Raw Normal View History

2019-03-26 18:28:37 +00:00
#pragma once
#include <Processors/Formats/IOutputFormat.h>
#include <Common/ConcurrentBoundedQueue.h>
#include <DataStreams/BlockStreamProfileInfo.h>
2019-04-05 10:52:07 +00:00
#include <IO/WriteBuffer.h>
2019-03-26 18:28:37 +00:00
namespace DB
{
class LazyOutputFormat : public IOutputFormat
{
public:
2019-04-05 11:43:28 +00:00
explicit LazyOutputFormat(Block header)
: IOutputFormat(std::move(header), out), queue(1), finished_processing(false) {}
2019-03-26 18:28:37 +00:00
2019-04-05 10:52:07 +00:00
String getName() const override { return "LazyOutputFormat"; }
2019-03-26 18:28:37 +00:00
Block getBlock(UInt64 milliseconds = 0);
Block getTotals();
Block getExtremes();
2019-04-05 11:43:28 +00:00
bool isFinished() { return finished_processing; }
2019-03-26 18:28:37 +00:00
BlockStreamProfileInfo & getProfileInfo() { return info; }
protected:
void consume(Chunk chunk) override { queue.push(chunk); }
void consumeTotals(Chunk chunk) override { totals = std::move(chunk); }
void consumeExtremes(Chunk chunk) override { extremes = std::move(chunk); }
void finalize() override
{
2019-04-05 11:43:28 +00:00
finished_processing = true;
2019-03-26 18:28:37 +00:00
/// In case we are waiting for result.
queue.push({});
}
private:
ConcurrentBoundedQueue<Chunk> queue;
Chunk totals;
Chunk extremes;
2019-04-05 10:52:07 +00:00
/// Is not used.
static WriteBuffer out;
2019-03-26 18:28:37 +00:00
BlockStreamProfileInfo info;
2019-04-05 11:43:28 +00:00
std::atomic<bool> finished_processing;
2019-03-26 18:28:37 +00:00
};
}