2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/SquashingBlockOutputStream.h>
|
2016-07-07 01:57:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-09-19 11:06:42 +00:00
|
|
|
SquashingBlockOutputStream::SquashingBlockOutputStream(BlockOutputStreamPtr & dst, const Block & header_, size_t min_block_size_rows, size_t min_block_size_bytes)
|
|
|
|
: output(dst), header(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());
|
2017-04-01 07:20:54 +00:00
|
|
|
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()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (all_written)
|
|
|
|
return;
|
2016-07-07 01:57:48 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
all_written = true;
|
2016-07-07 01:57:48 +00:00
|
|
|
|
2017-04-01 07:20:54 +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()
|
|
|
|
{
|
2017-07-12 00:41:14 +00:00
|
|
|
if (!disable_flush)
|
|
|
|
finalize();
|
2017-04-01 07:20:54 +00:00
|
|
|
output->flush();
|
2016-07-07 01:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SquashingBlockOutputStream::writePrefix()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
output->writePrefix();
|
2016-07-07 01:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SquashingBlockOutputStream::writeSuffix()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
finalize();
|
|
|
|
output->writeSuffix();
|
2016-07-07 01:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|