ClickHouse/dbms/src/DataStreams/SquashingBlockOutputStream.h

40 lines
933 B
C++
Raw Normal View History

2016-07-07 01:57:48 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <DataStreams/SquashingTransform.h>
2016-07-07 01:57:48 +00:00
namespace DB
{
/** Merging consecutive blocks of stream to specified minimum size.
*/
class SquashingBlockOutputStream : public IBlockOutputStream
{
public:
SquashingBlockOutputStream(BlockOutputStreamPtr & dst, const Block & header, size_t min_block_size_rows, size_t min_block_size_bytes);
2016-07-07 01:57:48 +00:00
2018-09-08 19:23:48 +00:00
Block getHeader() const override { return header; }
void write(const Block & block) override;
2016-07-07 01:57:48 +00:00
void flush() override;
void writePrefix() override;
void writeSuffix() override;
2016-07-07 01:57:48 +00:00
/// Don't write blocks less than specified size even when flush method was called by user.
void disableFlush() { disable_flush = true; }
2016-07-07 01:57:48 +00:00
private:
BlockOutputStreamPtr output;
2018-09-08 19:23:48 +00:00
Block header;
2016-07-07 01:57:48 +00:00
SquashingTransform transform;
bool all_written = false;
2016-07-07 01:57:48 +00:00
void finalize();
bool disable_flush = false;
2016-07-07 01:57:48 +00:00
};
}