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

70 lines
1.8 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/Interpreters/evaluateMissingDefaults.h>
2012-08-13 20:16:06 +00:00
#include <DB/Columns/ColumnConst.h>
#include <DB/Storages/ColumnDefault.h>
2012-08-13 20:16:06 +00:00
namespace DB
{
/** Добавляет в блок недостающие столбцы со значениями по-умолчанию.
* Эти столбцы - материалированные (не константы).
*/
class AddingDefaultBlockInputStream : public IProfilingBlockInputStream
{
public:
AddingDefaultBlockInputStream(
BlockInputStreamPtr input_,
NamesAndTypesListPtr required_columns_,
const ColumnDefaults & column_defaults_,
const Context & context_)
: required_columns(required_columns_),
column_defaults(column_defaults_), context(context_)
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
}
AddingDefaultBlockInputStream(BlockInputStreamPtr input_, NamesAndTypesListPtr required_columns_, const Context & context_)
: AddingDefaultBlockInputStream{input_, required_columns, {}, context}
{
}
String getName() const override { return "AddingDefaultBlockInputStream"; }
2012-10-20 02:10:47 +00:00
String getID() const override
{
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->name << ", " << it->type->getName();
res << ")";
return res.str();
}
2012-10-20 02:10:47 +00:00
protected:
Block readImpl() override
2012-08-13 20:16:06 +00:00
{
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;
evaluateMissingDefaults(res, *required_columns, column_defaults, context);
res.addDefaults(*required_columns);
2012-08-13 20:16:06 +00:00
return res;
}
private:
NamesAndTypesListPtr required_columns;
const ColumnDefaults & column_defaults;
Context context;
2012-08-13 20:16:06 +00:00
};
}