2014-01-16 15:19:50 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
2015-07-17 01:27:35 +00:00
|
|
|
|
#include <DB/Core/ColumnWithTypeAndName.h>
|
2014-01-16 15:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2014-01-17 15:19:20 +00:00
|
|
|
|
/** Добавляет в блок материализованный const column с заданным значением.
|
2014-01-16 15:19:50 +00:00
|
|
|
|
*/
|
|
|
|
|
template <typename ColumnType>
|
|
|
|
|
class AddingConstColumnBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AddingConstColumnBlockInputStream(
|
|
|
|
|
BlockInputStreamPtr input_,
|
|
|
|
|
DataTypePtr data_type_,
|
|
|
|
|
ColumnType value_,
|
|
|
|
|
String column_name_)
|
|
|
|
|
: data_type(data_type_), value(value_), column_name(column_name_)
|
|
|
|
|
{
|
|
|
|
|
children.push_back(input_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
|
String getName() const override { return "AddingConstColumn"; }
|
2014-01-16 15:19:50 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2014-01-16 15:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
|
|
|
|
res << "AddingConstColumn(" << children.back()->getID() << ")";
|
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
Block readImpl() override
|
2014-01-16 15:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Block res = children.back()->read();
|
|
|
|
|
if (!res)
|
|
|
|
|
return res;
|
2014-01-27 13:52:01 +00:00
|
|
|
|
ColumnPtr column_ptr = ColumnConst<ColumnType>(res.rows(), value, data_type).convertToFullColumn();
|
2016-08-04 23:35:07 +00:00
|
|
|
|
res.insert({column_ptr, data_type, column_name});
|
2014-01-16 15:19:50 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
DataTypePtr data_type;
|
|
|
|
|
ColumnType value;
|
|
|
|
|
String column_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|