#pragma once #include #include namespace DB { class Block; class StorageMergeTree; struct StorageSnapshot; using StorageSnapshotPtr = std::shared_ptr; class MergeTreeSink : public SinkToStorage { public: MergeTreeSink( StorageMergeTree & storage_, StorageMetadataPtr metadata_snapshot_, size_t max_parts_per_block_, ContextPtr context_); ~MergeTreeSink() override; String getName() const override { return "MergeTreeSink"; } void consume(Chunk & chunk) override; void onStart() override; void onFinish() override; private: StorageMergeTree & storage; StorageMetadataPtr metadata_snapshot; size_t max_parts_per_block; ContextPtr context; StorageSnapshotPtr storage_snapshot; UInt64 num_blocks_processed = 0; /// We can delay processing for previous chunk and start writing a new one. struct DelayedChunk; std::unique_ptr delayed_chunk; void finishDelayedChunk(); }; }