ClickHouse/dbms/include/DB/Storages/MergeTree/MergeTreeDataWriter.h

64 lines
1.7 KiB
C++
Raw Normal View History

2013-04-24 10:31:32 +00:00
#pragma once
2013-09-15 01:10:16 +00:00
#include <DB/IO/WriteBufferFromFile.h>
#include <DB/IO/CompressedWriteBuffer.h>
#include <DB/Columns/ColumnsNumber.h>
#include <DB/Interpreters/sortBlock.h>
2014-03-09 17:36:01 +00:00
#include <DB/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
2014-03-13 17:44:00 +00:00
struct BlockWithDateInterval
{
Block block;
2016-09-04 17:12:07 +00:00
UInt16 min_date = std::numeric_limits<UInt16>::max(); /// For further updating, see updateDates method.
UInt16 max_date = std::numeric_limits<UInt16>::min();
2014-03-13 17:44:00 +00:00
2016-09-04 17:12:07 +00:00
BlockWithDateInterval() = default;
2014-03-13 17:44:00 +00:00
BlockWithDateInterval(const Block & block_, UInt16 min_date_, UInt16 max_date_)
2016-09-04 17:12:07 +00:00
: block(block_), min_date(min_date_), max_date(max_date_) {}
void updateDates(UInt16 date)
{
if (date < min_date)
min_date = date;
if (date > max_date)
max_date = date;
}
2014-03-13 17:44:00 +00:00
};
using BlocksWithDateIntervals = std::list<BlockWithDateInterval>;
2014-03-13 17:44:00 +00:00
2014-03-13 12:48:07 +00:00
/** Записывает новые куски с данными в merge-дерево.
*/
class MergeTreeDataWriter
{
public:
2014-05-08 07:12:01 +00:00
MergeTreeDataWriter(MergeTreeData & data_) : data(data_), log(&Logger::get(data.getLogName() + " (Writer)")) {}
2014-03-13 12:48:07 +00:00
2016-09-04 17:12:07 +00:00
/** Split the block to blocks, each of them must be written as separate part.
* (split rows by months)
* Works deterministically: if same block was passed, function will return same result in same order.
2014-03-13 12:48:07 +00:00
*/
BlocksWithDateIntervals splitBlockIntoParts(const Block & block);
2014-03-13 12:48:07 +00:00
2016-09-04 17:12:07 +00:00
/** All rows must correspond to same month.
* 'temp_index' - value for 'left' and 'right' for new part. Could be changed later at rename.
* Returns part with name starting with 'tmp_', yet not added to MergeTreeData.
2014-03-13 12:48:07 +00:00
*/
2015-08-17 21:09:36 +00:00
MergeTreeData::MutableDataPartPtr writeTempPart(BlockWithDateInterval & block, Int64 temp_index);
2014-03-13 12:48:07 +00:00
private:
MergeTreeData & data;
2014-03-03 18:55:39 +00:00
2014-03-13 17:44:00 +00:00
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
}