2011-11-06 06:22:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Преобразует столбцы-константы в полноценные столбцы ("материализует" их).
|
|
|
|
*/
|
|
|
|
class MaterializingBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MaterializingBlockInputStream(BlockInputStreamPtr input_)
|
|
|
|
{
|
2013-05-04 04:05:15 +00:00
|
|
|
children.push_back(input_);
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
String getName() const { return "MaterializingBlockInputStream"; }
|
|
|
|
|
2013-05-03 10:20:53 +00:00
|
|
|
String getID() const
|
|
|
|
{
|
|
|
|
std::stringstream res;
|
2013-05-04 05:20:07 +00:00
|
|
|
res << "Materializing(" << children.back()->getID() << ")";
|
2013-05-03 10:20:53 +00:00
|
|
|
return res.str();
|
|
|
|
}
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
protected:
|
2011-11-06 06:22:52 +00:00
|
|
|
Block readImpl()
|
|
|
|
{
|
2013-05-04 05:20:07 +00:00
|
|
|
Block res = children.back()->read();
|
2011-11-06 06:22:52 +00:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
size_t columns = res.columns();
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
{
|
|
|
|
ColumnPtr col = res.getByPosition(i).column;
|
|
|
|
if (col->isConst())
|
|
|
|
res.getByPosition(i).column = dynamic_cast<IColumnConst &>(*col).convertToFullColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|