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>
|
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;
|
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;
|
2011-09-24 20:32:41 +00:00
|
|
|
/// тип возвращаемого значения
|
|
|
|
DataTypePtr return_type;
|
|
|
|
/// номер столбца возвращаемого значения
|
|
|
|
size_t return_column_number;
|
2011-08-09 19:19:00 +00:00
|
|
|
|
2010-06-25 16:36:13 +00:00
|
|
|
ASTFunction() {}
|
2011-08-13 21:05:18 +00:00
|
|
|
ASTFunction(StringRange range_) : IAST(range_) {}
|
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
|
|
|
{
|
|
|
|
std::stringstream s;
|
2012-10-29 02:58:52 +00:00
|
|
|
s << name;
|
|
|
|
|
|
|
|
if (parameters)
|
|
|
|
{
|
|
|
|
s << "(";
|
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())
|
|
|
|
s << ", ";
|
|
|
|
s << (*it)->getColumnName();
|
|
|
|
}
|
|
|
|
s << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
s << "(";
|
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())
|
|
|
|
s << ", ";
|
|
|
|
s << (*it)->getColumnName();
|
|
|
|
}
|
|
|
|
s << ")";
|
2012-10-29 02:58:52 +00:00
|
|
|
|
2011-09-26 01:50:32 +00:00
|
|
|
return s.str();
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|