2011-09-19 01:42:16 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
2011-08-09 19:19:00 +00:00
|
|
|
#include <DB/Functions/IFunction.h>
|
2011-09-19 01:42:16 +00:00
|
|
|
#include <DB/AggregateFunctions/IAggregateFunction.h>
|
2013-05-04 15:44:58 +00:00
|
|
|
#include <DB/IO/WriteBufferFromString.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Применение функции или оператора
|
|
|
|
*/
|
|
|
|
class ASTFunction : public IAST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// имя функции
|
|
|
|
String name;
|
2011-08-13 21:05:18 +00:00
|
|
|
/// аргументы
|
2010-06-24 19:12:10 +00:00
|
|
|
ASTPtr arguments;
|
2012-10-29 02:58:52 +00:00
|
|
|
/// параметры - для параметрических агрегатных функций. Пример: quantile(0.9)(x) - то, что в первых скобках - параметры.
|
|
|
|
ASTPtr parameters;
|
2011-11-06 04:21:09 +00:00
|
|
|
/// алиас, если есть
|
|
|
|
String alias;
|
2013-05-24 10:49:19 +00:00
|
|
|
|
|
|
|
bool is_aggregate_function;
|
|
|
|
bool is_lambda_expression;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
/// сама функция
|
|
|
|
FunctionPtr function;
|
2011-09-19 01:42:16 +00:00
|
|
|
/// или агрегатная функция
|
|
|
|
AggregateFunctionPtr aggregate_function;
|
2013-05-08 09:52:02 +00:00
|
|
|
/// или лямбда-выражение (ColumnExpression)
|
|
|
|
ColumnPtr column_expression;
|
2011-09-24 20:32:41 +00:00
|
|
|
/// тип возвращаемого значения
|
|
|
|
DataTypePtr return_type;
|
2011-08-09 19:19:00 +00:00
|
|
|
|
2013-05-24 10:49:19 +00:00
|
|
|
ASTFunction() : is_aggregate_function(false), is_lambda_expression(false) {}
|
|
|
|
ASTFunction(StringRange range_) : IAST(range_), is_aggregate_function(false), is_lambda_expression(false) {}
|
2011-08-09 19:19:00 +00:00
|
|
|
|
2012-12-27 16:23:12 +00:00
|
|
|
String getColumnName() const
|
2011-09-26 01:50:32 +00:00
|
|
|
{
|
2013-05-04 15:44:58 +00:00
|
|
|
String res;
|
|
|
|
WriteBufferFromString wb(res);
|
|
|
|
writeString(name, wb);
|
2012-10-29 02:58:52 +00:00
|
|
|
|
|
|
|
if (parameters)
|
|
|
|
{
|
2013-05-04 15:44:58 +00:00
|
|
|
writeChar('(', wb);
|
2012-12-27 16:23:12 +00:00
|
|
|
for (ASTs::const_iterator it = parameters->children.begin(); it != parameters->children.end(); ++it)
|
2012-10-29 02:58:52 +00:00
|
|
|
{
|
|
|
|
if (it != parameters->children.begin())
|
2013-05-15 22:58:57 +00:00
|
|
|
writeCString(", ", wb);
|
2013-05-04 15:44:58 +00:00
|
|
|
writeString((*it)->getColumnName(), wb);
|
2012-10-29 02:58:52 +00:00
|
|
|
}
|
2013-05-04 15:44:58 +00:00
|
|
|
writeChar(')', wb);
|
2012-10-29 02:58:52 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 15:44:58 +00:00
|
|
|
writeChar('(', wb);
|
2012-12-27 16:23:12 +00:00
|
|
|
for (ASTs::const_iterator it = arguments->children.begin(); it != arguments->children.end(); ++it)
|
2011-09-26 01:50:32 +00:00
|
|
|
{
|
|
|
|
if (it != arguments->children.begin())
|
2013-05-15 22:58:57 +00:00
|
|
|
writeCString(", ", wb);
|
2013-05-04 15:44:58 +00:00
|
|
|
writeString((*it)->getColumnName(), wb);
|
2011-09-26 01:50:32 +00:00
|
|
|
}
|
2013-05-04 15:44:58 +00:00
|
|
|
writeChar(')', wb);
|
|
|
|
|
|
|
|
return res;
|
2011-09-26 01:50:32 +00:00
|
|
|
}
|
2011-09-25 03:37:09 +00:00
|
|
|
|
2012-12-27 16:23:12 +00:00
|
|
|
String getAlias() const { return alias.empty() ? getColumnName() : alias; }
|
2011-11-06 04:21:09 +00:00
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2012-12-27 16:23:12 +00:00
|
|
|
String getID() const { return "Function_" + name; }
|
2011-12-12 06:15:34 +00:00
|
|
|
|
|
|
|
ASTPtr clone() const
|
|
|
|
{
|
|
|
|
ASTFunction * res = new ASTFunction(*this);
|
|
|
|
res->children.clear();
|
|
|
|
|
2012-10-29 02:58:52 +00:00
|
|
|
if (arguments) { res->arguments = arguments->clone(); res->children.push_back(res->arguments); }
|
|
|
|
if (parameters) { res->parameters = parameters->clone(); res->children.push_back(res->parameters); }
|
2011-12-12 06:15:34 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|