Removed copy-paste [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-11-01 06:09:06 +03:00
parent 6aff58c747
commit 175af4b2e9
4 changed files with 36 additions and 51 deletions

View File

@ -1,6 +1,6 @@
#include <DataStreams/MaterializingBlockInputStream.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataStreams/materializeBlock.h>
namespace DB
{
@ -24,31 +24,7 @@ String MaterializingBlockInputStream::getID() const
Block MaterializingBlockInputStream::readImpl()
{
Block res = children.back()->read();
if (!res)
return res;
size_t columns = res.columns();
for (size_t i = 0; i < columns; ++i)
{
auto & element = res.safeGetByPosition(i);
auto & src = element.column;
ColumnPtr converted = src->convertToFullColumnIfConst();
if (converted)
{
src = converted;
auto & type = element.type;
if (type->isNull())
{
/// A ColumnNull that is converted to a full column
/// has the type DataTypeNullable(DataTypeUInt8).
type = std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt8>());
}
}
}
return res;
return materializeBlock(children.back()->read());
}
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <Core/Block.h>
#include <DataStreams/materializeBlock.h>
#include <DataStreams/IBlockOutputStream.h>
@ -15,24 +15,18 @@ public:
MaterializingBlockOutputStream(const BlockOutputStreamPtr & output)
: output{output} {}
void write(const Block & block) override
{
output->write(materialize(block));
}
void flush() override { output->flush(); }
void writePrefix() override { output->writePrefix(); }
void writeSuffix() override { output->writeSuffix(); }
void setRowsBeforeLimit(size_t rows_before_limit) override { output->setRowsBeforeLimit(rows_before_limit); }
void setTotals(const Block & totals) override { output->setTotals(materialize(totals)); }
void setExtremes(const Block & extremes) override { output->setExtremes(materialize(extremes)); }
void onProgress(const Progress & progress) override { output->onProgress(progress); }
String getContentType() const override { return output->getContentType(); }
void write(const Block & block) override { output->write(materializeBlock(block)); }
void flush() override { output->flush(); }
void writePrefix() override { output->writePrefix(); }
void writeSuffix() override { output->writeSuffix(); }
void setRowsBeforeLimit(size_t rows_before_limit) override { output->setRowsBeforeLimit(rows_before_limit); }
void setTotals(const Block & totals) override { output->setTotals(materializeBlock(totals)); }
void setExtremes(const Block & extremes) override { output->setExtremes(materializeBlock(extremes)); }
void onProgress(const Progress & progress) override { output->onProgress(progress); }
String getContentType() const override { return output->getContentType(); }
private:
BlockOutputStreamPtr output;
static Block materialize(const Block & original_block);
};
}

View File

@ -1,25 +1,27 @@
#include <DataStreams/MaterializingBlockOutputStream.h>
#include <DataStreams/materializeBlock.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypesNumber.h>
#include <ext/range.h>
namespace DB
{
Block MaterializingBlockOutputStream::materialize(const Block & original_block)
Block materializeBlock(const Block & block)
{
/// copy block to get rid of const
auto block = original_block;
if (!block)
return block;
for (const auto i : ext::range(0, block.columns()))
Block res = block;
size_t columns = res.columns();
for (size_t i = 0; i < columns; ++i)
{
auto & element = block.safeGetByPosition(i);
auto & element = res.getByPosition(i);
auto & src = element.column;
ColumnPtr converted = src->convertToFullColumnIfConst();
if (converted)
{
src = converted;
auto & type = element.type;
if (type->isNull())
{
@ -30,7 +32,7 @@ Block MaterializingBlockOutputStream::materialize(const Block & original_block)
}
}
return block;
return res;
}
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <Core/Block.h>
namespace DB
{
/** Converts columns-constants to full columns ("materializes" them).
*/
Block materializeBlock(const Block & block);
}