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

99 lines
2.3 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>
#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:
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
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
{
2016-05-03 23:19:14 +00:00
ORDINARY = 0,
CASE_WITH_EXPR,
CASE_WITHOUT_EXPR,
CASE_ARRAY
};
2016-05-03 23:19:14 +00:00
Genus genus{Genus::ORDINARY};
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;
protected:
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
};
template <typename... Args>
ASTPtr makeASTFunction(const String & name, Args &&... args)
{
const auto function = new ASTFunction{};
ASTPtr result{function};
function->name = name;
function->arguments = new ASTExpressionList{};
function->children.push_back(function->arguments);
function->arguments->children = { std::forward<Args>(args)... };
return result;
}
template <typename... Args>
ASTPtr makeASTFunction(const String & name, const StringRange & function_range,
const StringRange & arguments_range, Args &&... args)
{
const auto function = new ASTFunction{function_range};
ASTPtr result{function};
function->name = name;
function->arguments = new ASTExpressionList{arguments_range};
function->children.push_back(function->arguments);
function->arguments->children = { std::forward<Args>(args)... };
return result;
}
2010-06-24 19:12:10 +00:00
}