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

68 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
}
String getName() const override { return "AddingDefault"; }
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;
2015-09-11 14:26:26 +00:00
/** @todo if somehow block does not contain values for implicitly-defaulted columns that are prerequisites
* for explicitly-defaulted ones, exception will be thrown during evaluating such columns
* (implicitly-defaulted columns are evaluated on the line after following one. */
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;
2015-11-15 09:17:51 +00:00
const ColumnDefaults column_defaults;
Context context;
2012-08-13 20:16:06 +00:00
};
}