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
|
|
|
|
{
|
|
|
|
|
2016-09-04 00:01:48 +00:00
|
|
|
/** 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:
|
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;
|
|
|
|
ASTPtr arguments;
|
2016-09-04 00:01:48 +00:00
|
|
|
/// parameters - for parametric aggregate function. Example: quantile(0.9)(x) - what in first parens are 'parameters'.
|
2012-10-29 02:58:52 +00:00
|
|
|
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
|
|
|
|
2016-09-04 00:01:48 +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;
|
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;
|
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
|
|
|
}
|