#pragma once #include #include #include #include #include #include namespace DB { class PartitionedSink : public SinkToStorage { public: static constexpr auto PARTITION_ID_WILDCARD = "{_partition_id}"; PartitionedSink(const ASTPtr & partition_by, ContextPtr context_, const Block & sample_block_); String getName() const override { return "PartitionedSink"; } void consume(Chunk chunk) override; void onFinish() override; virtual SinkPtr createSinkForPartition(const String & partition_id) = 0; static void validatePartitionKey(const String & str, bool allow_slash); static String replaceWildcards(const String & haystack, const String & partition_id); private: ContextPtr context; Block sample_block; ExpressionActionsPtr partition_by_expr; String partition_by_column_name; absl::flat_hash_map partition_id_to_sink; HashMapWithSavedHash partition_id_to_chunk_index; IColumn::Selector chunk_row_index_to_partition_index; Arena partition_keys_arena; SinkPtr getSinkForPartitionKey(StringRef partition_key); }; }