2014-01-16 15:19:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/ColumnWithTypeAndName.h>
|
2014-01-16 15:19:50 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** Adds a materialized const column to the block with a specified value.
|
2014-01-16 15:19:50 +00:00
|
|
|
*/
|
2017-07-21 06:35:58 +00:00
|
|
|
template <typename T>
|
2019-01-23 14:48:50 +00:00
|
|
|
class AddingConstColumnBlockInputStream : public IBlockInputStream
|
2014-01-16 15:19:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
AddingConstColumnBlockInputStream(
|
|
|
|
BlockInputStreamPtr input_,
|
|
|
|
DataTypePtr data_type_,
|
2017-07-21 06:35:58 +00:00
|
|
|
T value_,
|
2017-04-01 07:20:54 +00:00
|
|
|
String column_name_)
|
|
|
|
: data_type(data_type_), value(value_), column_name(column_name_)
|
|
|
|
{
|
|
|
|
children.push_back(input_);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override { return "AddingConstColumn"; }
|
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override
|
2018-01-06 18:10:44 +00:00
|
|
|
{
|
|
|
|
Block res = children.back()->getHeader();
|
2018-01-09 00:19:58 +00:00
|
|
|
res.insert({data_type->createColumn(), data_type, column_name});
|
2018-01-06 18:10:44 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-01-16 15:19:50 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override
|
|
|
|
{
|
|
|
|
Block res = children.back()->read();
|
|
|
|
if (!res)
|
|
|
|
return res;
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-12-10 22:44:04 +00:00
|
|
|
res.insert({data_type->createColumnConst(res.rows(), value)->convertToFullColumnIfConst(), data_type, column_name});
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
|
|
|
}
|
2014-01-16 15:19:50 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
DataTypePtr data_type;
|
2017-07-21 06:35:58 +00:00
|
|
|
T value;
|
2017-04-01 07:20:54 +00:00
|
|
|
String column_name;
|
2014-01-16 15:19:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|