2011-08-14 00:49:30 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
|
|
2013-06-03 10:18:41 +00:00
|
|
|
|
#include <DB/Interpreters/ExpressionActions.h>
|
2011-09-04 21:23:19 +00:00
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2011-08-14 00:49:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Выполняет над блоком вычисление некоторого выражения.
|
|
|
|
|
* Выражение состоит из идентификаторов столбцов из блока, констант, обычных функций.
|
2015-04-16 06:12:35 +00:00
|
|
|
|
* Например: hits * 2 + 3, url LIKE '%yandex%'
|
2011-08-14 00:49:30 +00:00
|
|
|
|
* Выражение не меняет количество строк в потоке, и обрабатывает каждую строку независимо от других.
|
|
|
|
|
*/
|
2011-09-04 21:23:19 +00:00
|
|
|
|
class ExpressionBlockInputStream : public IProfilingBlockInputStream
|
2011-08-14 00:49:30 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2013-06-03 10:18:41 +00:00
|
|
|
|
ExpressionBlockInputStream(BlockInputStreamPtr input_, ExpressionActionsPtr expression_)
|
|
|
|
|
: expression(expression_)
|
2011-09-04 21:23:19 +00:00
|
|
|
|
{
|
2013-05-04 04:05:15 +00:00
|
|
|
|
children.push_back(input_);
|
2011-09-04 21:23:19 +00:00
|
|
|
|
}
|
2011-08-14 00:49:30 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getName() const override { return "ExpressionBlockInputStream"; }
|
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-06-03 10:18:41 +00:00
|
|
|
|
res << "Expression(" << children.back()->getID() << ", " << expression->getID() << ")";
|
2013-05-03 10:20:53 +00:00
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
const Block & getTotals() override
|
2013-09-08 08:27:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (IProfilingBlockInputStream * child = dynamic_cast<IProfilingBlockInputStream *>(&*children.back()))
|
|
|
|
|
{
|
|
|
|
|
totals = child->getTotals();
|
|
|
|
|
|
|
|
|
|
if (totals)
|
|
|
|
|
expression->execute(totals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totals;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
|
protected:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
Block readImpl() override
|
2011-08-14 00:49:30 +00:00
|
|
|
|
{
|
2013-05-04 05:20:07 +00:00
|
|
|
|
Block res = children.back()->read();
|
2011-08-14 00:49:30 +00:00
|
|
|
|
if (!res)
|
|
|
|
|
return res;
|
|
|
|
|
|
2013-06-03 10:18:41 +00:00
|
|
|
|
expression->execute(res);
|
2012-10-25 20:20:46 +00:00
|
|
|
|
|
2011-08-28 05:13:24 +00:00
|
|
|
|
return res;
|
2011-08-14 00:49:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2013-06-03 10:18:41 +00:00
|
|
|
|
ExpressionActionsPtr expression;
|
2011-08-14 00:49:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|