ASTFunction.h 1.7 KB
Newer Older
A
Alexey Milovidov 已提交
1
#pragma once
A
Alexey Milovidov 已提交
2

3 4
#include <Parsers/ASTWithAlias.h>
#include <Parsers/ASTExpressionList.h>
A
Amos Bird 已提交
5
#include <Parsers/ASTSelectWithUnionQuery.h>
A
Alexey Milovidov 已提交
6 7 8 9 10


namespace DB
{

A
Alexander Kuzmenkov 已提交
11 12
class ASTIdentifier;

13
/** AST for function application or operator.
A
Alexey Milovidov 已提交
14
  */
A
Alexey Milovidov 已提交
15
class ASTFunction : public ASTWithAlias
A
Alexey Milovidov 已提交
16 17
{
public:
18 19 20 21 22
    String name;
    ASTPtr arguments;
    /// parameters - for parametric aggregate function. Example: quantile(0.9)(x) - what in first parens are 'parameters'.
    ASTPtr parameters;

A
Alexander Kuzmenkov 已提交
23 24 25 26 27
    bool is_window_function = false;
    ASTIdentifier * window_name;
    ASTExpressionList * window_partition_by;
    ASTExpressionList * window_order_by;

28 29 30
    /// do not print empty parentheses if there are no args - compatibility with new AST for data types and engine names.
    bool no_empty_args = false;

31
    /** Get text identifying the AST node. */
32
    String getID(char delim) const override;
A
Alexey Milovidov 已提交
33

34
    ASTPtr clone() const override;
35

A
Amos Bird 已提交
36 37
    void updateTreeHashImpl(SipHash & hash_state) const override;

A
Amos Bird 已提交
38 39
    ASTSelectWithUnionQuery * tryGetQueryArgument() const;

40 41
    ASTPtr toLiteral() const;  // Try to convert functions like Array or Tuple to a literal form.

42
protected:
43
    void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
44
    void appendColumnNameImpl(WriteBuffer & ostr) const override;
A
Alexey Milovidov 已提交
45 46
};

47 48

template <typename... Args>
49
std::shared_ptr<ASTFunction> makeASTFunction(const String & name, Args &&... args)
50
{
51
    auto function = std::make_shared<ASTFunction>();
52

53 54 55
    function->name = name;
    function->arguments = std::make_shared<ASTExpressionList>();
    function->children.push_back(function->arguments);
56

57
    function->arguments->children = { std::forward<Args>(args)... };
58

A
Alexey Milovidov 已提交
59
    return function;
60 61
}

A
Alexey Milovidov 已提交
62
}