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:
|
2013-05-29 11:46:51 +00:00
|
|
|
enum FunctionKind
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
2014-02-28 13:09:43 +00:00
|
|
|
TABLE_FUNCTION,
|
2013-05-29 11:46:51 +00:00
|
|
|
FUNCTION,
|
|
|
|
AGGREGATE_FUNCTION,
|
|
|
|
LAMBDA_EXPRESSION,
|
|
|
|
ARRAY_JOIN,
|
|
|
|
};
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
/// имя функции
|
|
|
|
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
|
|
|
|
2013-05-29 11:46:51 +00:00
|
|
|
FunctionKind kind;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2013-05-29 11:46:51 +00:00
|
|
|
ASTFunction() : kind(UNKNOWN) {}
|
|
|
|
ASTFunction(StringRange range_) : IAST(range_), kind(UNKNOWN) {}
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|