From 175af4b2e9cec951ab97d15ab3149965731d252f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 1 Nov 2017 06:09:06 +0300 Subject: [PATCH] Removed copy-paste [#CLICKHOUSE-2]. --- .../MaterializingBlockInputStream.cpp | 30 ++----------------- .../MaterializingBlockOutputStream.h | 26 +++++++--------- ...kOutputStream.cpp => materializeBlock.cpp} | 18 ++++++----- dbms/src/DataStreams/materializeBlock.h | 13 ++++++++ 4 files changed, 36 insertions(+), 51 deletions(-) rename dbms/src/DataStreams/{MaterializingBlockOutputStream.cpp => materializeBlock.cpp} (63%) create mode 100644 dbms/src/DataStreams/materializeBlock.h diff --git a/dbms/src/DataStreams/MaterializingBlockInputStream.cpp b/dbms/src/DataStreams/MaterializingBlockInputStream.cpp index 640eb87b103..b7ae5c6c000 100644 --- a/dbms/src/DataStreams/MaterializingBlockInputStream.cpp +++ b/dbms/src/DataStreams/MaterializingBlockInputStream.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include + 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(std::make_shared()); - } - } - } - - return res; + return materializeBlock(children.back()->read()); } } diff --git a/dbms/src/DataStreams/MaterializingBlockOutputStream.h b/dbms/src/DataStreams/MaterializingBlockOutputStream.h index c71531d5338..2d8489156f4 100644 --- a/dbms/src/DataStreams/MaterializingBlockOutputStream.h +++ b/dbms/src/DataStreams/MaterializingBlockOutputStream.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include @@ -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); }; } diff --git a/dbms/src/DataStreams/MaterializingBlockOutputStream.cpp b/dbms/src/DataStreams/materializeBlock.cpp similarity index 63% rename from dbms/src/DataStreams/MaterializingBlockOutputStream.cpp rename to dbms/src/DataStreams/materializeBlock.cpp index fa5c53c8279..1368fce8f36 100644 --- a/dbms/src/DataStreams/MaterializingBlockOutputStream.cpp +++ b/dbms/src/DataStreams/materializeBlock.cpp @@ -1,25 +1,27 @@ -#include +#include #include #include -#include 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; } } diff --git a/dbms/src/DataStreams/materializeBlock.h b/dbms/src/DataStreams/materializeBlock.h new file mode 100644 index 00000000000..383be5d7c99 --- /dev/null +++ b/dbms/src/DataStreams/materializeBlock.h @@ -0,0 +1,13 @@ +#pragma once + +#include + + +namespace DB +{ + +/** Converts columns-constants to full columns ("materializes" them). + */ +Block materializeBlock(const Block & block); + +}