ClickHouse/src/Parsers/ASTFunction.h

79 lines
2.5 KiB
C++
Raw Normal View History

2011-09-19 01:42:16 +00:00
#pragma once
2010-06-24 19:12:10 +00:00
#include <Parsers/ASTWithAlias.h>
#include <Parsers/ASTExpressionList.h>
2020-09-09 07:41:38 +00:00
#include <Parsers/ASTSelectWithUnionQuery.h>
2010-06-24 19:12:10 +00:00
namespace DB
{
2020-12-16 21:44:05 +00:00
class ASTIdentifier;
/** 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:
String name;
ASTPtr arguments;
/// parameters - for parametric aggregate function. Example: quantile(0.9)(x) - what in first parens are 'parameters'.
ASTPtr parameters;
2020-12-16 21:44:05 +00:00
bool is_window_function = false;
2020-12-28 09:56:38 +00:00
// We have to make these fields ASTPtr because this is what the visitors
// expect. Some of them take const ASTPtr & (makes no sense), and some
// take ASTPtr & and modify it. I don't understand how the latter is
// compatible with also having an owning `children` array -- apparently it
// leads to some dangling children that are not referenced by the fields of
// the AST class itself. Some older code hints at the idea of having
// ownership in `children` only, and making the class fields to be raw
// pointers of proper type (see e.g. IAST::set), but this is not compatible
// with the visitor interface.
2021-01-13 19:29:52 +00:00
String window_name;
ASTPtr window_definition;
2020-12-16 21:44:05 +00:00
/// 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;
/** Get text identifying the AST node. */
String getID(char delim) const override;
2011-12-12 06:15:34 +00:00
ASTPtr clone() const override;
2020-08-20 02:01:40 +00:00
void updateTreeHashImpl(SipHash & hash_state) const override;
2020-09-09 07:41:38 +00:00
ASTSelectWithUnionQuery * tryGetQueryArgument() const;
ASTPtr toLiteral() const; // Try to convert functions like Array or Tuple to a literal form.
2020-12-22 01:37:45 +00:00
std::string getWindowDescription() const;
protected:
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
void appendColumnNameImpl(WriteBuffer & ostr) const override;
void appendColumnNameImpl(WriteBuffer & ostr, const Settings & settings) const override;
private:
void appendColumnNameImpl(WriteBuffer & ostr, const Settings * settings) const;
2010-06-24 19:12:10 +00:00
};
template <typename... Args>
std::shared_ptr<ASTFunction> makeASTFunction(const String & name, Args &&... args)
{
auto function = std::make_shared<ASTFunction>();
function->name = name;
function->arguments = std::make_shared<ASTExpressionList>();
function->children.push_back(function->arguments);
function->arguments->children = { std::forward<Args>(args)... };
2018-02-26 03:37:08 +00:00
return function;
}
2010-06-24 19:12:10 +00:00
}