#pragma once #include #include #include namespace DB { class QueryStatus; using QueryStatusPtr = std::shared_ptr; class ThreadStatus; /// Proxy class which counts number of written block, rows, bytes class CountingTransform final : public ExceptionKeepingTransform { public: explicit CountingTransform( const Block & header, ThreadStatus * thread_status_ = nullptr, std::shared_ptr quota_ = nullptr) : ExceptionKeepingTransform(header, header) , thread_status(thread_status_), quota(std::move(quota_)) {} String getName() const override { return "CountingTransform"; } void setProgressCallback(const ProgressCallback & callback) { progress_callback = callback; } void setProcessListElement(QueryStatusPtr elem) { process_elem = elem; } const Progress & getProgress() const { return progress; } void onConsume(Chunk chunk) override; GenerateResult onGenerate() override { GenerateResult res; res.chunk = std::move(cur_chunk); return res; } protected: Progress progress; ProgressCallback progress_callback; QueryStatusPtr process_elem; ThreadStatus * thread_status = nullptr; /// Quota is used to limit amount of written bytes. std::shared_ptr quota; Chunk cur_chunk; }; }