2014-03-13 12:48:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Storages/StorageMergeTree.h>
|
2014-05-08 07:30:00 +00:00
|
|
|
#include <iomanip>
|
2014-03-13 12:48:07 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class MergeTreeBlockOutputStream : public IBlockOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2014-03-19 10:45:13 +00:00
|
|
|
MergeTreeBlockOutputStream(StorageMergeTree & storage_)
|
|
|
|
: storage(storage_) {}
|
2014-03-13 12:48:07 +00:00
|
|
|
|
|
|
|
void write(const Block & block)
|
|
|
|
{
|
2014-03-19 10:45:13 +00:00
|
|
|
auto part_blocks = storage.writer.splitBlockIntoParts(block);
|
2014-03-13 17:44:00 +00:00
|
|
|
for (auto & current_block : part_blocks)
|
2014-03-13 12:48:07 +00:00
|
|
|
{
|
2014-05-27 08:43:01 +00:00
|
|
|
storage.data.delayInsertIfNeeded();
|
2014-04-11 16:56:49 +00:00
|
|
|
|
2014-03-13 12:48:07 +00:00
|
|
|
UInt64 temp_index = storage.increment.get();
|
2014-03-19 10:45:13 +00:00
|
|
|
MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block, temp_index);
|
|
|
|
storage.data.renameTempPartAndAdd(part, &storage.increment);
|
2014-07-03 08:51:11 +00:00
|
|
|
storage.merge_task_handle->wake();
|
2014-03-13 12:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
StorageMergeTree & storage;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|