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

54 lines
1.4 KiB
C
Raw Normal View History

2011-08-28 05:13:24 +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-28 05:13:24 +00:00
namespace DB
{
using Poco::SharedPtr;
/** Выбирает из блока только столбцы, являющиеся результатом вычисления выражения.
* Следует применять после ExpressionBlockInputStream.
*/
2011-09-04 21:23:19 +00:00
class ProjectionBlockInputStream : public IProfilingBlockInputStream
2011-08-28 05:13:24 +00:00
{
public:
2011-09-04 05:14:52 +00:00
ProjectionBlockInputStream(
BlockInputStreamPtr input_,
SharedPtr<Expression> expression_,
2011-11-06 04:21:09 +00:00
bool without_duplicates_and_aliases_ = false,
2011-09-25 03:37:09 +00:00
unsigned part_id_ = 0,
ASTPtr subtree_ = NULL)
2011-11-06 04:21:09 +00:00
: input(input_), expression(expression_), without_duplicates_and_aliases(without_duplicates_and_aliases_), part_id(part_id_), subtree(subtree_)
2011-09-04 21:23:19 +00:00
{
children.push_back(input);
}
2011-08-28 05:13:24 +00:00
2011-09-04 21:23:19 +00:00
Block readImpl()
2011-08-28 05:13:24 +00:00
{
Block res = input->read();
if (!res)
return res;
2011-11-06 04:21:09 +00:00
return expression->projectResult(res, without_duplicates_and_aliases, part_id, subtree);
2011-08-28 05:13:24 +00:00
}
2011-09-04 21:23:19 +00:00
String getName() const { return "ProjectionBlockInputStream"; }
2011-11-06 04:21:09 +00:00
BlockInputStreamPtr clone() { return new ProjectionBlockInputStream(input, expression, without_duplicates_and_aliases, part_id, subtree); }
2011-10-24 12:10:59 +00:00
2011-08-28 05:13:24 +00:00
private:
BlockInputStreamPtr input;
SharedPtr<Expression> expression;
2011-11-06 04:21:09 +00:00
bool without_duplicates_and_aliases;
2011-08-28 05:13:24 +00:00
unsigned part_id;
2011-09-25 03:37:09 +00:00
ASTPtr subtree;
2011-08-28 05:13:24 +00:00
};
}