2012-08-13 20:16:06 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2014-10-23 13:53:16 +00:00
|
|
|
|
#include <DB/Interpreters/evaluateMissingDefaults.h>
|
2012-08-13 20:16:06 +00:00
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
|
|
|
|
|
2014-09-30 03:08:47 +00:00
|
|
|
|
#include <DB/Storages/ColumnDefault.h>
|
2012-08-13 20:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Добавляет в блок недостающие столбцы со значениями по-умолчанию.
|
|
|
|
|
* Эти столбцы - материалированные (не константы).
|
|
|
|
|
*/
|
|
|
|
|
class AddingDefaultBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AddingDefaultBlockInputStream(
|
|
|
|
|
BlockInputStreamPtr input_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2014-10-03 10:25:05 +00:00
|
|
|
|
AddingDefaultBlockInputStream(BlockInputStreamPtr input_, NamesAndTypesListPtr required_columns_, const Context & context_)
|
2015-01-21 04:00:20 +00:00
|
|
|
|
: AddingDefaultBlockInputStream{input_, required_columns_, ColumnDefaults{}, context_}
|
2014-10-03 10:25:05 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
|
String getName() const override { return "AddingDefault"; }
|
2012-10-20 02:10:47 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2013-05-03 10:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
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:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
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. */
|
2014-10-23 13:53:16 +00:00
|
|
|
|
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;
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const ColumnDefaults & column_defaults;
|
|
|
|
|
Context context;
|
2012-08-13 20:16:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|