ClickHouse/dbms/include/DB/DataStreams/MaterializingBlockOutputStream.h
2015-10-29 00:21:18 +03:00

45 lines
1014 B
C++

#pragma once
#include <DB/Columns/ColumnConst.h>
#include <DB/DataStreams/IBlockOutputStream.h>
#include <ext/range.hpp>
namespace DB
{
/** Преобразует столбцы-константы в полноценные столбцы ("материализует" их).
*/
class MaterializingBlockOutputStream : public IBlockOutputStream
{
public:
MaterializingBlockOutputStream(const BlockOutputStreamPtr & output)
: output{output} {}
void write(const Block & original_block) override
{
/// copy block to get rid of const
auto block = original_block;
for (const auto i : ext::range(0, block.columns()))
{
auto & src = block.getByPosition(i).column;
ColumnPtr converted = src->convertToFullColumnIfConst();
if (converted)
src = converted;
}
output->write(block);
}
void flush() override { output->flush(); }
void writePrefix() override { output->writePrefix(); }
void writeSuffix() override { output->writeSuffix(); }
private:
BlockOutputStreamPtr output;
};
}