2014-03-04 11:26:55 +00:00
|
|
|
|
#pragma once
|
2014-06-12 04:04:47 +00:00
|
|
|
|
|
2017-02-02 22:08:19 +00:00
|
|
|
|
#include <Poco/Logger.h>
|
2014-03-04 11:26:55 +00:00
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2014-07-06 19:48:39 +00:00
|
|
|
|
#include <DB/Interpreters/ExpressionAnalyzer.h>
|
2014-06-12 04:04:47 +00:00
|
|
|
|
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-05-31 01:04:34 +00:00
|
|
|
|
/** Отдаёт без изменений данные из потока блоков, но
|
|
|
|
|
* в функции readPrefix или перед чтением первого блока
|
|
|
|
|
* инициализирует все переданные множества.
|
2014-03-04 11:26:55 +00:00
|
|
|
|
*/
|
|
|
|
|
class CreatingSetsBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 19:48:39 +00:00
|
|
|
|
CreatingSetsBlockInputStream(
|
|
|
|
|
BlockInputStreamPtr input,
|
2014-11-28 14:09:18 +00:00
|
|
|
|
const SubqueriesForSets & subqueries_for_sets_,
|
2014-07-06 19:48:39 +00:00
|
|
|
|
const Limits & limits)
|
|
|
|
|
: subqueries_for_sets(subqueries_for_sets_),
|
|
|
|
|
max_rows_to_transfer(limits.max_rows_to_transfer),
|
|
|
|
|
max_bytes_to_transfer(limits.max_bytes_to_transfer),
|
|
|
|
|
transfer_overflow_mode(limits.transfer_overflow_mode)
|
2014-03-04 11:26:55 +00:00
|
|
|
|
{
|
2014-07-06 19:48:39 +00:00
|
|
|
|
for (auto & elem : subqueries_for_sets)
|
2015-01-28 02:37:05 +00:00
|
|
|
|
if (elem.second.source)
|
|
|
|
|
children.push_back(elem.second.source);
|
2014-06-12 04:04:47 +00:00
|
|
|
|
|
2014-03-04 11:26:55 +00:00
|
|
|
|
children.push_back(input);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
|
String getName() const override { return "CreatingSets"; }
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2014-03-04 11:26:55 +00:00
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
|
|
|
|
res << "CreatingSets(";
|
|
|
|
|
|
|
|
|
|
Strings children_ids(children.size());
|
|
|
|
|
for (size_t i = 0; i < children.size(); ++i)
|
|
|
|
|
children_ids[i] = children[i]->getID();
|
|
|
|
|
|
|
|
|
|
/// Будем считать, что порядок создания множеств не имеет значения.
|
|
|
|
|
std::sort(children_ids.begin(), children_ids.end() - 1);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < children_ids.size(); ++i)
|
|
|
|
|
res << (i == 0 ? "" : ", ") << children_ids[i];
|
|
|
|
|
|
|
|
|
|
res << ")";
|
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 09:55:24 +00:00
|
|
|
|
/// Берёт totals только из основного источника, а не из источников подзапросов.
|
|
|
|
|
const Block & getTotals() override;
|
|
|
|
|
|
2014-03-04 11:26:55 +00:00
|
|
|
|
protected:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
Block readImpl() override;
|
2016-05-31 01:04:34 +00:00
|
|
|
|
void readPrefixImpl() override;
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2014-07-06 19:48:39 +00:00
|
|
|
|
SubqueriesForSets subqueries_for_sets;
|
2014-06-12 04:04:47 +00:00
|
|
|
|
bool created = false;
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
2014-07-06 19:48:39 +00:00
|
|
|
|
size_t max_rows_to_transfer;
|
|
|
|
|
size_t max_bytes_to_transfer;
|
|
|
|
|
OverflowMode transfer_overflow_mode;
|
|
|
|
|
|
|
|
|
|
size_t rows_to_transfer = 0;
|
|
|
|
|
size_t bytes_to_transfer = 0;
|
|
|
|
|
|
2014-06-12 04:04:47 +00:00
|
|
|
|
Logger * log = &Logger::get("CreatingSetsBlockInputStream");
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
2016-05-31 01:04:34 +00:00
|
|
|
|
void createAll();
|
|
|
|
|
void createOne(SubqueryForSet & subquery);
|
2014-03-04 11:26:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|