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

50 lines
1.5 KiB
C
Raw Normal View History

2011-08-14 00:49:30 +00:00
#pragma once
#include <Poco/SharedPtr.h>
#include <DB/Interpreters/Expression.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;
/** Выполняет над блоком вычисление некоторого выражения.
* Выражение состоит из идентификаторов столбцов из блока, констант, обычных функций.
* Например: hits * 2 + 3, instr("yandex", url)
* Выражение не меняет количество строк в потоке, и обрабатывает каждую строку независимо от других.
2011-08-28 05:13:24 +00:00
* part_id - идентификатор части выражения, которую надо вычислять.
* Например, может потребоваться вычислить только часть выражения в секции WHERE.
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:
2011-08-28 05:13:24 +00:00
ExpressionBlockInputStream(BlockInputStreamPtr input_, SharedPtr<Expression> expression_, unsigned part_id_ = 0)
2011-09-04 21:23:19 +00:00
: input(input_), expression(expression_), part_id(part_id_)
{
children.push_back(input);
}
2011-08-14 00:49:30 +00:00
2011-09-04 21:23:19 +00:00
Block readImpl()
2011-08-14 00:49:30 +00:00
{
Block res = input->read();
if (!res)
return res;
2011-08-28 05:13:24 +00:00
expression->execute(res, part_id);
return res;
2011-08-14 00:49:30 +00:00
}
2011-09-04 21:23:19 +00:00
String getName() const { return "ExpressionBlockInputStream"; }
2011-08-14 00:49:30 +00:00
private:
2011-08-28 02:22:23 +00:00
BlockInputStreamPtr input;
2011-08-14 00:49:30 +00:00
SharedPtr<Expression> expression;
2011-08-28 05:13:24 +00:00
unsigned part_id;
2011-08-14 00:49:30 +00:00
};
}