#pragma once #include #include #include #include namespace DB { class LazyOutputFormat : public IOutputFormat { public: explicit LazyOutputFormat(Block header) : IOutputFormat(std::move(header), out), queue(1), finished_processing(false) {} String getName() const override { return "LazyOutputFormat"; } Block getBlock(UInt64 milliseconds = 0); Block getTotals(); Block getExtremes(); bool isFinished() { return finished_processing; } 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 { finished_processing = true; /// In case we are waiting for result. queue.push({}); } private: ConcurrentBoundedQueue queue; Chunk totals; Chunk extremes; /// Is not used. static WriteBuffer out; BlockStreamProfileInfo info; std::atomic finished_processing; }; }