ClickHouse/dbms/include/DB/Parsers/ASTFunction.h

85 lines
2.0 KiB
C
Raw Normal View History

2011-09-19 01:42:16 +00:00
#pragma once
2010-06-24 19:12:10 +00:00
2014-07-03 22:39:13 +00:00
#include <DB/Parsers/ASTWithAlias.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
{
/** Применение функции или оператора
*/
2014-07-03 22:39:13 +00:00
class ASTFunction : public ASTWithAlias
2010-06-24 19:12:10 +00:00
{
public:
enum FunctionKind
{
UNKNOWN,
TABLE_FUNCTION,
FUNCTION,
AGGREGATE_FUNCTION,
LAMBDA_EXPRESSION,
ARRAY_JOIN,
};
2014-07-03 22:39:13 +00:00
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;
/// параметры - для параметрических агрегатных функций. Пример: quantile(0.9)(x) - то, что в первых скобках - параметры.
ASTPtr parameters;
2014-07-03 22:39:13 +00:00
FunctionKind kind;
2010-06-24 19:12:10 +00:00
ASTFunction() : kind(UNKNOWN) {}
2014-07-03 22:39:13 +00:00
ASTFunction(StringRange range_) : ASTWithAlias(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);
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)
{
if (it != parameters->children.begin())
writeCString(", ", wb);
2013-05-04 15:44:58 +00:00
writeString((*it)->getColumnName(), wb);
}
2013-05-04 15:44:58 +00:00
writeChar(')', wb);
}
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())
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
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();
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
};
}