ClickHouse/dbms/include/DB/DataStreams/AddingConstColumnBlockInputStream.h
Sergey Fedorov 9cc974568e Merge
2014-01-17 15:19:20 +00:00

57 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <Poco/SharedPtr.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/Columns/ColumnConst.h>
#include <DB/Core/ColumnWithNameAndType.h>
namespace DB
{
/** Добавляет в блок материализованный const column с заданным значением.
*/
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_);
}
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<ColumnType> (res.rows(), value, data_type))->convertToFullColumn();
ColumnWithNameAndType column(column_ptr, data_type, column_name);
res.insert(column);
return res;
}
private:
DataTypePtr data_type;
ColumnType value;
String column_name;
};
}