2018-01-19 05:26:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
2016-07-06 21:48:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-07-07 01:57:48 +00:00
|
|
|
|
|
|
|
/** Merging consecutive passed blocks to specified minimum size.
|
|
|
|
*
|
|
|
|
* (But if one of input blocks has already at least specified size,
|
|
|
|
* then don't merge it with neighbours, even if neighbours are small.)
|
|
|
|
*
|
|
|
|
* Used to prepare blocks to adequate size for INSERT queries,
|
|
|
|
* because such storages as Memory, StripeLog, Log, TinyLog...
|
|
|
|
* store or compress data in blocks exactly as passed to it,
|
|
|
|
* and blocks of small size are not efficient.
|
|
|
|
*
|
|
|
|
* Order of data is kept.
|
|
|
|
*/
|
2016-07-06 21:48:11 +00:00
|
|
|
class SquashingTransform
|
|
|
|
{
|
|
|
|
public:
|
2016-07-07 01:57:48 +00:00
|
|
|
/// Conditions on rows and bytes are OR-ed. If one of them is zero, then corresponding condition is ignored.
|
2022-02-28 09:55:31 +00:00
|
|
|
SquashingTransform(size_t min_block_size_rows_, size_t min_block_size_bytes_);
|
2016-07-06 21:48:11 +00:00
|
|
|
|
2016-07-07 01:57:48 +00:00
|
|
|
/** Add next block and possibly returns squashed block.
|
|
|
|
* At end, you need to pass empty block. As the result for last (empty) block, you will get last Result with ready = true.
|
|
|
|
*/
|
2020-04-21 14:59:57 +00:00
|
|
|
Block add(Block && block);
|
|
|
|
Block add(const Block & block);
|
2016-07-06 21:48:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
size_t min_block_size_rows;
|
|
|
|
size_t min_block_size_bytes;
|
|
|
|
|
2020-04-21 14:59:57 +00:00
|
|
|
Block accumulated_block;
|
2016-07-06 21:48:11 +00:00
|
|
|
|
2020-04-21 14:59:57 +00:00
|
|
|
template <typename ReferenceType>
|
|
|
|
Block addImpl(ReferenceType block);
|
2020-04-21 16:27:56 +00:00
|
|
|
|
2020-04-21 14:59:57 +00:00
|
|
|
template <typename ReferenceType>
|
|
|
|
void append(ReferenceType block);
|
2016-07-06 21:48:11 +00:00
|
|
|
|
2020-04-21 14:59:57 +00:00
|
|
|
bool isEnoughSize(const Block & block);
|
2016-07-06 21:48:11 +00:00
|
|
|
bool isEnoughSize(size_t rows, size_t bytes) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|