ClickHouse/dbms/include/DB/DataStreams/AddingDefaultBlockInputStream.h

57 lines
1.2 KiB
C
Raw Normal View History

2012-08-13 20:16:06 +00:00
#pragma once
#include <Poco/SharedPtr.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/Columns/ColumnConst.h>
namespace DB
{
/** Добавляет в блок недостающие столбцы со значениями по-умолчанию.
* Эти столбцы - материалированные (не константы).
*/
class AddingDefaultBlockInputStream : public IProfilingBlockInputStream
{
public:
AddingDefaultBlockInputStream(
BlockInputStreamPtr input_,
NamesAndTypesListPtr required_columns_)
2013-05-04 04:05:15 +00:00
: required_columns(required_columns_)
2012-08-13 20:16:06 +00:00
{
2013-05-04 04:05:15 +00:00
children.push_back(input_);
2012-08-13 20:16:06 +00:00
}
2012-10-20 02:10:47 +00:00
String getName() const { return "AddingDefaultBlockInputStream"; }
String getID() const
{
std::stringstream res;
2013-05-04 05:20:07 +00:00
res << "AddingDefault(" << children.back()->getID();
for (NamesAndTypesList::const_iterator it = required_columns->begin(); it != required_columns->end(); ++it)
res << ", " << it->first << ", " << it->second->getName();
res << ")";
return res.str();
}
2012-10-20 02:10:47 +00:00
protected:
2012-08-13 20:16:06 +00:00
Block readImpl()
{
2013-05-04 05:20:07 +00:00
Block res = children.back()->read();
2012-08-13 20:16:06 +00:00
if (!res)
return res;
res.addDefaults(required_columns);
2012-08-13 20:16:06 +00:00
return res;
}
private:
NamesAndTypesListPtr required_columns;
};
}