2021-10-26 12:22:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-10 20:06:23 +00:00
|
|
|
#include <Common/HashTable/HashMap.h>
|
|
|
|
#include <Common/Arena.h>
|
|
|
|
#include <absl/container/flat_hash_map.h>
|
2021-10-25 16:23:44 +00:00
|
|
|
#include <Processors/Sinks/SinkToStorage.h>
|
|
|
|
#include <Interpreters/ExpressionAnalyzer.h>
|
|
|
|
#include <Interpreters/Context_fwd.h>
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-05-06 17:30:18 +00:00
|
|
|
void onException() override;
|
|
|
|
|
2021-10-25 16:23:44 +00:00
|
|
|
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;
|
|
|
|
|
2022-02-10 20:06:23 +00:00
|
|
|
absl::flat_hash_map<StringRef, SinkPtr> partition_id_to_sink;
|
|
|
|
HashMapWithSavedHash<StringRef, size_t> partition_id_to_chunk_index;
|
|
|
|
IColumn::Selector chunk_row_index_to_partition_index;
|
|
|
|
Arena partition_keys_arena;
|
|
|
|
|
|
|
|
SinkPtr getSinkForPartitionKey(StringRef partition_key);
|
2021-10-25 16:23:44 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|