diff --git a/dbms/include/DB/DataStreams/AddingConstColumnBlockInputStream.h b/dbms/include/DB/DataStreams/AddingConstColumnBlockInputStream.h new file mode 100644 index 00000000000..6f22eeb3657 --- /dev/null +++ b/dbms/include/DB/DataStreams/AddingConstColumnBlockInputStream.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include +#include +#include + +namespace DB +{ + +/** Добавляет в блок const column с заданным значением. + */ +template +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_) + { + std :: cerr << column_name << " " << value << std :: endl; + children.push_back(input_); + } + + String getName() const { return "AddingConstColumnBlockInputStream"; } + + String getID() const + { + std::stringstream res; + res << "AddingConstColumn(" << children.back()->getID() << ")"; + return res.str(); + } + +protected: + Block readImpl() + { + Block res = children.back()->read(); + if (!res) + return res; + ColumnPtr column_ptr = new ColumnConst (res.rows(), value, data_type); + ColumnWithNameAndType column(column_ptr, data_type, column_name); + + res.insert(column); + return res; + } + +private: + DataTypePtr data_type; + ColumnType value; + String column_name; +}; + +}