2011-09-19 01:42:16 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
2021-11-26 15:49:40 +00:00
|
|
|
#include <Parsers/ASTIdentifier_fwd.h>
|
|
|
|
#include <Parsers/ASTWithAlias.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-11-26 18:27:16 +00:00
|
|
|
class ASTSelectWithUnionQuery;
|
2020-12-16 21:44:05 +00:00
|
|
|
|
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:
|
|
|
|
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;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-12-16 21:44:05 +00:00
|
|
|
bool is_window_function = false;
|
2020-12-28 09:56:38 +00:00
|
|
|
|
2022-06-16 13:29:56 +00:00
|
|
|
bool compute_after_window_functions = false;
|
|
|
|
|
2022-07-14 11:20:16 +00:00
|
|
|
bool is_lambda_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
|
|
|
|
2020-12-04 02:15:44 +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;
|
|
|
|
|
2022-11-14 18:28:19 +00:00
|
|
|
/// Specifies where this function-like expression is used.
|
2022-11-11 15:26:04 +00:00
|
|
|
enum class Kind
|
|
|
|
{
|
|
|
|
ORDINARY_FUNCTION,
|
|
|
|
WINDOW_FUNCTION,
|
|
|
|
LAMBDA_FUNCTION,
|
|
|
|
TABLE_ENGINE,
|
|
|
|
DATABASE_ENGINE,
|
|
|
|
BACKUP_NAME,
|
|
|
|
};
|
|
|
|
Kind kind = Kind::ORDINARY_FUNCTION;
|
|
|
|
|
2016-09-04 00:01:48 +00:00
|
|
|
/** Get text identifying the AST node. */
|
2018-12-07 12:34:40 +00:00
|
|
|
String getID(char delim) 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
|
|
|
|
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;
|
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
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;
|
|
|
|
|
2022-11-11 15:26:04 +00:00
|
|
|
bool hasSecretParts() 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;
|
2018-06-27 16:34:11 +00:00
|
|
|
void appendColumnNameImpl(WriteBuffer & ostr) const override;
|
2022-06-13 22:39:18 +00:00
|
|
|
private:
|
|
|
|
void finishFormatWithWindow(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2014-09-25 15:00:12 +00:00
|
|
|
|
|
|
|
template <typename... Args>
|
2018-11-06 18:25:36 +00:00
|
|
|
std::shared_ptr<ASTFunction> makeASTFunction(const String & name, Args &&... args)
|
2014-09-25 15:00:12 +00:00
|
|
|
{
|
2020-07-01 14:04:08 +00:00
|
|
|
auto function = std::make_shared<ASTFunction>();
|
2014-09-25 15:00:12 +00:00
|
|
|
|
|
|
|
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)... };
|
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
return function;
|
2014-09-29 13:32:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 20:17:02 +00:00
|
|
|
/// ASTFunction Helpers: hide casts and semantic.
|
|
|
|
|
|
|
|
String getFunctionName(const IAST * ast);
|
|
|
|
std::optional<String> tryGetFunctionName(const IAST * ast);
|
|
|
|
bool tryGetFunctionNameInto(const IAST * ast, String & name);
|
|
|
|
|
|
|
|
inline String getFunctionName(const ASTPtr & ast) { return getFunctionName(ast.get()); }
|
|
|
|
inline std::optional<String> tryGetFunctionName(const ASTPtr & ast) { return tryGetFunctionName(ast.get()); }
|
|
|
|
inline bool tryGetFunctionNameInto(const ASTPtr & ast, String & name) { return tryGetFunctionNameInto(ast.get(), name); }
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
}
|