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"; }
|
|
|
|
|
|
2013-05-03 10:20:53 +00:00
|
|
|
|
String getID() const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
2013-05-04 05:20:07 +00:00
|
|
|
|
res << "AddingDefault(" << children.back()->getID();
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
|
|
|
|
for (NamesAndTypesList::const_iterator it = required_columns->begin(); it != required_columns->end(); ++it)
|
2014-07-09 11:45:51 +00:00
|
|
|
|
res << ", " << it->name << ", " << it->type->getName();
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2013-10-28 16:09:42 +00:00
|
|
|
|
res.addDefaults(required_columns);
|
2012-08-13 20:16:06 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
NamesAndTypesListPtr required_columns;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|