ClickHouse/dbms/DataStreams/SquashingBlockOutputStream.cpp

55 lines
1.1 KiB
C++
Raw Normal View History

#include <DataStreams/SquashingBlockOutputStream.h>
2016-07-07 01:57:48 +00:00
namespace DB
{
2019-08-03 11:02:40 +00:00
SquashingBlockOutputStream::SquashingBlockOutputStream(BlockOutputStreamPtr dst, Block header_, size_t min_block_size_rows, size_t min_block_size_bytes)
: output(std::move(dst)), header(std::move(header_)), transform(min_block_size_rows, min_block_size_bytes)
2016-07-07 01:57:48 +00:00
{
}
void SquashingBlockOutputStream::write(const Block & block)
{
2018-09-09 02:23:24 +00:00
SquashingTransform::Result result = transform.add(Block(block).mutateColumns());
if (result.ready)
2018-09-08 19:23:48 +00:00
output->write(header.cloneWithColumns(std::move(result.columns)));
2016-07-07 01:57:48 +00:00
}
void SquashingBlockOutputStream::finalize()
{
if (all_written)
return;
2016-07-07 01:57:48 +00:00
all_written = true;
2016-07-07 01:57:48 +00:00
SquashingTransform::Result result = transform.add({});
2018-09-08 19:23:48 +00:00
if (result.ready && !result.columns.empty())
output->write(header.cloneWithColumns(std::move(result.columns)));
2016-07-07 01:57:48 +00:00
}
void SquashingBlockOutputStream::flush()
{
if (!disable_flush)
finalize();
output->flush();
2016-07-07 01:57:48 +00:00
}
void SquashingBlockOutputStream::writePrefix()
{
output->writePrefix();
2016-07-07 01:57:48 +00:00
}
void SquashingBlockOutputStream::writeSuffix()
{
finalize();
output->writeSuffix();
2016-07-07 01:57:48 +00:00
}
}