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

84 lines
1.9 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
{
/** AST for function application or operator.
2010-06-24 19:12:10 +00:00
*/
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;
ASTPtr arguments;
/// parameters - for parametric aggregate function. Example: quantile(0.9)(x) - what in first parens are 'parameters'.
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
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
/** Get text identifying the AST node. */
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;
2010-06-24 19:12:10 +00:00
};
template <typename... Args>
ASTPtr makeASTFunction(const String & name, Args &&... args)
{
const auto function = std::make_shared<ASTFunction>();
ASTPtr result{function};
function->name = name;
function->arguments = std::make_shared<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 = std::make_shared<ASTFunction>(function_range);
ASTPtr result{function};
function->name = name;
function->arguments = std::make_shared<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
}