2014-10-13 14:35:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
|
|
|
#include <DB/DataStreams/IBlockOutputStream.h>
|
2015-10-05 00:33:43 +00:00
|
|
|
#include <ext/range.hpp>
|
2014-10-13 14:35:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Преобразует столбцы-константы в полноценные столбцы ("материализует" их).
|
|
|
|
*/
|
|
|
|
class MaterializingBlockOutputStream : public IBlockOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2015-01-27 00:52:03 +00:00
|
|
|
MaterializingBlockOutputStream(const BlockOutputStreamPtr & output)
|
|
|
|
: output{output} {}
|
2014-10-13 14:35:40 +00:00
|
|
|
|
|
|
|
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()))
|
|
|
|
{
|
2015-10-28 21:21:18 +00:00
|
|
|
auto & src = block.getByPosition(i).column;
|
|
|
|
ColumnPtr converted = src->convertToFullColumnIfConst();
|
|
|
|
if (converted)
|
|
|
|
src = converted;
|
2014-10-13 14:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output->write(block);
|
|
|
|
}
|
|
|
|
|
2015-01-27 00:52:03 +00:00
|
|
|
void flush() override { output->flush(); }
|
|
|
|
|
|
|
|
void writePrefix() override { output->writePrefix(); }
|
|
|
|
void writeSuffix() override { output->writeSuffix(); }
|
|
|
|
|
|
|
|
private:
|
2014-10-13 14:35:40 +00:00
|
|
|
BlockOutputStreamPtr output;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|