2013-04-24 10:31:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-08-19 18:11:20 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Core/Row.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedWriteBuffer.h>
|
2013-09-15 01:10:16 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2013-09-15 01:10:16 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/sortBlock.h>
|
2013-09-15 01:10:16 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2013-04-24 10:31:32 +00:00
|
|
|
|
2013-09-15 01:10:16 +00:00
|
|
|
|
2013-04-24 10:31:32 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2014-03-09 17:36:01 +00:00
|
|
|
|
2017-08-18 19:46:26 +00:00
|
|
|
struct BlockWithPartition
|
2014-03-13 17:44:00 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Block block;
|
2017-08-19 18:11:20 +00:00
|
|
|
Row partition;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-08-19 18:11:20 +00:00
|
|
|
BlockWithPartition(Block && block_, Row && partition_)
|
2017-08-18 19:46:26 +00:00
|
|
|
: block(block_), partition(std::move(partition_))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
}
|
2014-03-13 17:44:00 +00:00
|
|
|
};
|
|
|
|
|
2017-08-19 18:11:20 +00:00
|
|
|
using BlocksWithPartition = std::vector<BlockWithPartition>;
|
2014-03-13 17:44:00 +00:00
|
|
|
|
2018-05-07 02:01:11 +00:00
|
|
|
/** Writes new parts of data to the merge tree.
|
2014-03-13 12:48:07 +00:00
|
|
|
*/
|
|
|
|
class MergeTreeDataWriter
|
|
|
|
{
|
|
|
|
public:
|
2020-05-30 21:57:37 +00:00
|
|
|
MergeTreeDataWriter(MergeTreeData & data_) : data(data_), log(&Poco::Logger::get(data.getLogName() + " (Writer)")) {}
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/** Split the block to blocks, each of them must be written as separate part.
|
2017-08-14 18:16:11 +00:00
|
|
|
* (split rows by partition)
|
2017-04-01 07:20:54 +00:00
|
|
|
* Works deterministically: if same block was passed, function will return same result in same order.
|
|
|
|
*/
|
2020-06-17 10:34:23 +00:00
|
|
|
BlocksWithPartition splitBlockIntoParts(const Block & block, size_t max_parts, const StorageMetadataPtr & metadata_snapshot);
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
/** All rows must correspond to same partition.
|
|
|
|
* Returns part with unique name starting with 'tmp_', yet not added to MergeTreeData.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2020-06-16 15:51:29 +00:00
|
|
|
MergeTreeData::MutableDataPartPtr writeTempPart(BlockWithPartition & block, const StorageMetadataPtr & metadata_snapshot);
|
2014-03-13 12:48:07 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData & data;
|
2014-03-03 18:55:39 +00:00
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log;
|
2013-04-24 10:31:32 +00:00
|
|
|
};
|
2014-03-13 17:44:00 +00:00
|
|
|
|
2013-04-24 10:31:32 +00:00
|
|
|
}
|