1#pragma once
2
3#include <Core/Block.h>
4#include <Core/Row.h>
5
6#include <IO/WriteBufferFromFile.h>
7#include <Compression/CompressedWriteBuffer.h>
8
9#include <Columns/ColumnsNumber.h>
10
11#include <Interpreters/sortBlock.h>
12#include <Interpreters/Context.h>
13
14#include <Storages/MergeTree/MergeTreeData.h>
15
16
17namespace DB
18{
19
20struct BlockWithPartition
21{
22 Block block;
23 Row partition;
24
25 BlockWithPartition(Block && block_, Row && partition_)
26 : block(block_), partition(std::move(partition_))
27 {
28 }
29};
30
31using BlocksWithPartition = std::vector<BlockWithPartition>;
32
33/** Writes new parts of data to the merge tree.
34 */
35class MergeTreeDataWriter
36{
37public:
38 MergeTreeDataWriter(MergeTreeData & data_) : data(data_), log(&Logger::get(data.getLogName() + " (Writer)")) {}
39
40 /** Split the block to blocks, each of them must be written as separate part.
41 * (split rows by partition)
42 * Works deterministically: if same block was passed, function will return same result in same order.
43 */
44 BlocksWithPartition splitBlockIntoParts(const Block & block, size_t max_parts);
45
46 /** All rows must correspond to same partition.
47 * Returns part with unique name starting with 'tmp_', yet not added to MergeTreeData.
48 */
49 MergeTreeData::MutableDataPartPtr writeTempPart(BlockWithPartition & block);
50
51private:
52 MergeTreeData & data;
53
54 Logger * log;
55};
56
57}
58