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>
|
2014-09-25 15:00:12 +00:00
|
|
|
#include <DB/Parsers/ASTExpressionList.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:
|
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,
|
|
|
|
};
|
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;
|
2012-10-29 02:58:52 +00:00
|
|
|
/// параметры - для параметрических агрегатных функций. Пример: quantile(0.9)(x) - то, что в первых скобках - параметры.
|
|
|
|
ASTPtr parameters;
|
2014-07-03 22:39:13 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
FunctionKind kind{UNKNOWN};
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
enum class Genus
|
2015-04-30 05:45:34 +00:00
|
|
|
{
|
2016-05-03 23:19:14 +00:00
|
|
|
ORDINARY = 0,
|
|
|
|
CASE_WITH_EXPR,
|
|
|
|
CASE_WITHOUT_EXPR,
|
|
|
|
CASE_ARRAY
|
|
|
|
};
|
2015-04-30 05:45:34 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
Genus genus{Genus::ORDINARY};
|
2015-05-03 09:13:08 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
public:
|
|
|
|
ASTFunction() = default;
|
|
|
|
ASTFunction(const StringRange range_) : ASTWithAlias(range_) {}
|
2014-12-17 15:26:24 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
String getColumnName() const override;
|
2011-12-12 06:15:34 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
|
|
|
String getID() const override;
|
2011-12-12 06:15:34 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
ASTPtr clone() const override;
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
protected:
|
2015-08-06 23:46:15 +00:00
|
|
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
2016-05-03 23:19:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void formatCase(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2014-09-25 15:00:12 +00:00
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
ASTPtr makeASTFunction(const String & name, Args &&... args)
|
|
|
|
{
|
2016-05-28 15:42:22 +00:00
|
|
|
const auto function = std::make_shared<ASTFunction>();
|
2014-09-25 15:00:12 +00:00
|
|
|
ASTPtr result{function};
|
|
|
|
|
|
|
|
function->name = name;
|
2016-05-28 15:42:22 +00:00
|
|
|
function->arguments = std::make_shared<ASTExpressionList>();
|
2014-09-25 15:00:12 +00:00
|
|
|
function->children.push_back(function->arguments);
|
|
|
|
|
|
|
|
function->arguments->children = { std::forward<Args>(args)... };
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-29 13:32:16 +00:00
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
ASTPtr makeASTFunction(const String & name, const StringRange & function_range,
|
|
|
|
const StringRange & arguments_range, Args &&... args)
|
|
|
|
{
|
2016-05-28 15:42:22 +00:00
|
|
|
const auto function = std::make_shared<ASTFunction>(function_range);
|
2014-09-29 13:32:16 +00:00
|
|
|
ASTPtr result{function};
|
|
|
|
|
|
|
|
function->name = name;
|
2016-05-28 15:42:22 +00:00
|
|
|
function->arguments = std::make_shared<ASTExpressionList>(arguments_range);
|
2014-09-29 13:32:16 +00:00
|
|
|
function->children.push_back(function->arguments);
|
|
|
|
|
|
|
|
function->arguments->children = { std::forward<Args>(args)... };
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
}
|