mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Removed copy-paste [#CLICKHOUSE-2].
This commit is contained in:
parent
6aff58c747
commit
175af4b2e9
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
13
dbms/src/DataStreams/materializeBlock.h
Normal file
13
dbms/src/DataStreams/materializeBlock.h
Normal 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);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user