Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::WindowExpression Class Reference
Inheritance diagram for duckdb::WindowExpression:
Collaboration diagram for duckdb::WindowExpression:

Public Member Functions

 WindowExpression (ExpressionType type, string catalog_name, string schema_name, const string &function_name)
 
bool IsWindow () const override
 Returns true if the expression has a window function or not.
 
string ToString () const override
 Convert the Expression to a String.
 
bool HasBoundedParts ()
 
unique_ptr< ParsedExpressionCopy () const override
 Create a copy of this expression.
 
void Serialize (Serializer &serializer) const override
 
- Public Member Functions inherited from duckdb::ParsedExpression
 ParsedExpression (ExpressionType type, ExpressionClass expression_class)
 Create an Expression.
 
bool IsAggregate () const override
 Returns true if this expression is an aggregate or not.
 
bool HasSubquery () const override
 Returns true if the query contains a subquery.
 
bool IsScalar () const override
 Returns true if expression does not contain a group ref or col ref or parameter.
 
bool HasParameter () const override
 Returns true if the expression has a parameter.
 
bool Equals (const BaseExpression &other) const override
 Returns true if this expression is equal to another expression.
 
hash_t Hash () const override
 
- Public Member Functions inherited from duckdb::BaseExpression
 BaseExpression (ExpressionType type, ExpressionClass expression_class)
 Create an Expression.
 
ExpressionClass GetExpressionClass () const
 Returns the class of the expression.
 
ExpressionType GetExpressionType () const
 Returns the type of the expression.
 
void SetExpressionTypeUnsafe (ExpressionType new_type)
 
optional_idx GetQueryLocation () const
 Returns the location in the query (if any)
 
void SetQueryLocation (optional_idx location)
 Sets the location in the query.
 
bool HasAlias () const
 Returns true if the expression has a non-empty alias.
 
const string & GetAlias () const
 Returns the alias of the expression.
 
void SetAlias (const string &alias_p)
 Sets the alias of the expression.
 
void SetAlias (string &&alias_p)
 Sets the alias of the expression.
 
void ClearAlias ()
 Clears the alias of the expression.
 
virtual string GetName () const
 Get the name of the expression.
 
void Print () const
 Print the expression to stdout.
 
bool operator== (const BaseExpression &rhs) const
 
virtual void Verify () const
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Static Public Member Functions

static bool Equal (const WindowExpression &a, const WindowExpression &b)
 
static unique_ptr< ParsedExpressionDeserialize (Deserializer &deserializer)
 
static const WindowFunctionDefinitionWindowFunctions ()
 
static ExpressionType WindowToExpressionType (string &fun_name)
 
static string ToUnits (const WindowBoundary boundary, const WindowBoundary rows, const WindowBoundary range, const WindowBoundary groups)
 
template<class T , class BASE , class ORDER_NODE >
static string ToString (const T &entry, const string &schema, const string &function_name)
 
- Static Public Member Functions inherited from duckdb::ParsedExpression
static unique_ptr< ParsedExpressionDeserialize (Deserializer &deserializer)
 
static bool Equals (const unique_ptr< ParsedExpression > &left, const unique_ptr< ParsedExpression > &right)
 
static bool ListEquals (const vector< unique_ptr< ParsedExpression > > &left, const vector< unique_ptr< ParsedExpression > > &right)
 
- Static Public Member Functions inherited from duckdb::BaseExpression
static bool Equals (const BaseExpression &left, const BaseExpression &right)
 

Public Attributes

string catalog
 Catalog of the aggregate function.
 
string schema
 Schema of the aggregate function.
 
string function_name
 Name of the aggregate function.
 
vector< unique_ptr< ParsedExpression > > children
 The child expression of the main window function.
 
vector< unique_ptr< ParsedExpression > > partitions
 The set of expressions to partition by.
 
vector< OrderByNodeorders
 The set of ordering clauses.
 
unique_ptr< ParsedExpressionfilter_expr
 Expression representing a filter, only used for aggregates.
 
bool ignore_nulls = false
 True to ignore NULL values.
 
bool distinct = false
 Whether or not the aggregate function is distinct, only used for aggregates.
 
WindowBoundary start = WindowBoundary::INVALID
 The window boundaries.
 
WindowBoundary end = WindowBoundary::INVALID
 
WindowExcludeMode exclude_clause = WindowExcludeMode::NO_OTHER
 The EXCLUDE clause.
 
unique_ptr< ParsedExpressionstart_expr
 
unique_ptr< ParsedExpressionend_expr
 
unique_ptr< ParsedExpressionoffset_expr
 Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions.
 
unique_ptr< ParsedExpressiondefault_expr
 
vector< OrderByNodearg_orders
 
- Public Attributes inherited from duckdb::BaseExpression
ExpressionType type
 Type of the expression.
 
ExpressionClass expression_class
 The expression class of the node.
 
string alias
 The alias of the expression,.
 
optional_idx query_location
 The location in the query (if any)
 

Static Public Attributes

static constexpr const ExpressionClass TYPE = ExpressionClass::WINDOW
 

Private Member Functions

 WindowExpression (ExpressionType type)
 

Additional Inherited Members

- Protected Member Functions inherited from duckdb::ParsedExpression
void CopyProperties (const ParsedExpression &other)
 

Detailed Description

The WindowExpression represents a window function in the query. They are a special case of aggregates which is why they inherit from them.

Member Function Documentation

◆ IsWindow()

bool duckdb::WindowExpression::IsWindow ( ) const
inlineoverridevirtual

Returns true if the expression has a window function or not.

Reimplemented from duckdb::ParsedExpression.

60886 {
60887 return true;
60888 }

◆ ToString() [1/2]

string duckdb::WindowExpression::ToString ( ) const
overridevirtual

Convert the Expression to a String.

Implements duckdb::BaseExpression.

◆ Copy()

unique_ptr< ParsedExpression > duckdb::WindowExpression::Copy ( ) const
overridevirtual

Create a copy of this expression.

Implements duckdb::ParsedExpression.

◆ Serialize()

void duckdb::WindowExpression::Serialize ( Serializer serializer) const
overridevirtual

Reimplemented from duckdb::ParsedExpression.

◆ ToUnits()

static string duckdb::WindowExpression::ToUnits ( const WindowBoundary  boundary,
const WindowBoundary  rows,
const WindowBoundary  range,
const WindowBoundary  groups 
)
inlinestatic
60907 {
60908 if (boundary == rows) {
60909 return "ROWS";
60910 } else if (boundary == range) {
60911 return "RANGE";
60912 } else {
60913 return "GROUPS";
60914 }
60915 }
int rows

◆ ToString() [2/2]

template<class T , class BASE , class ORDER_NODE >
static string duckdb::WindowExpression::ToString ( const T &  entry,
const string &  schema,
const string &  function_name 
)
inlinestatic
60918 {
60919 // Start with function call
60920 string result = schema.empty() ? function_name : schema + "." + function_name;
60921 result += "(";
60922 if (entry.children.size()) {
60923 // Only one DISTINCT is allowed (on the first argument)
60924 int distincts = entry.distinct ? 0 : 1;
60925 result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr<BASE> &child) {
60926 return (distincts++ ? "" : "DISTINCT ") + child->ToString();
60927 });
60928 }
60929 // Lead/Lag extra arguments
60930 if (entry.offset_expr.get()) {
60931 result += ", ";
60932 result += entry.offset_expr->ToString();
60933 }
60934 if (entry.default_expr.get()) {
60935 result += ", ";
60936 result += entry.default_expr->ToString();
60937 }
60938 // ORDER BY arguments
60939 if (!entry.arg_orders.empty()) {
60940 result += " ORDER BY ";
60941 result += StringUtil::Join(entry.arg_orders, entry.arg_orders.size(), ", ",
60942 [](const ORDER_NODE &order) { return order.ToString(); });
60943 }
60944
60945 // IGNORE NULLS
60946 if (entry.ignore_nulls) {
60947 result += " IGNORE NULLS";
60948 }
60949 // FILTER
60950 if (entry.filter_expr) {
60951 result += ") FILTER (WHERE " + entry.filter_expr->ToString();
60952 }
60953
60954 // Over clause
60955 result += ") OVER (";
60956 string sep;
60957
60958 // Partitions
60959 if (!entry.partitions.empty()) {
60960 result += "PARTITION BY ";
60961 result += StringUtil::Join(entry.partitions, entry.partitions.size(), ", ",
60962 [](const unique_ptr<BASE> &partition) { return partition->ToString(); });
60963 sep = " ";
60964 }
60965
60966 // Orders
60967 if (!entry.orders.empty()) {
60968 result += sep;
60969 result += "ORDER BY ";
60970 result += StringUtil::Join(entry.orders, entry.orders.size(), ", ",
60971 [](const ORDER_NODE &order) { return order.ToString(); });
60972 sep = " ";
60973 }
60974
60975 // Rows/Range
60976 string units = "ROWS";
60977 string from;
60978 switch (entry.start) {
60979 case WindowBoundary::CURRENT_ROW_RANGE:
60980 case WindowBoundary::CURRENT_ROW_ROWS:
60981 case WindowBoundary::CURRENT_ROW_GROUPS:
60982 from = "CURRENT ROW";
60983 units = ToUnits(entry.start, WindowBoundary::CURRENT_ROW_ROWS, WindowBoundary::CURRENT_ROW_RANGE,
60984 WindowBoundary::CURRENT_ROW_GROUPS);
60985 break;
60986 case WindowBoundary::UNBOUNDED_PRECEDING:
60987 if (entry.end != WindowBoundary::CURRENT_ROW_RANGE) {
60988 from = "UNBOUNDED PRECEDING";
60989 }
60990 break;
60991 case WindowBoundary::EXPR_PRECEDING_ROWS:
60992 case WindowBoundary::EXPR_PRECEDING_RANGE:
60993 case WindowBoundary::EXPR_PRECEDING_GROUPS:
60994 from = entry.start_expr->ToString() + " PRECEDING";
60995 units = ToUnits(entry.start, WindowBoundary::EXPR_PRECEDING_ROWS, WindowBoundary::EXPR_PRECEDING_RANGE,
60996 WindowBoundary::EXPR_PRECEDING_GROUPS);
60997 break;
60998 case WindowBoundary::EXPR_FOLLOWING_ROWS:
60999 case WindowBoundary::EXPR_FOLLOWING_RANGE:
61000 case WindowBoundary::EXPR_FOLLOWING_GROUPS:
61001 from = entry.start_expr->ToString() + " FOLLOWING";
61002 units = ToUnits(entry.start, WindowBoundary::EXPR_FOLLOWING_ROWS, WindowBoundary::EXPR_FOLLOWING_RANGE,
61003 WindowBoundary::EXPR_FOLLOWING_GROUPS);
61004 break;
61005 case WindowBoundary::UNBOUNDED_FOLLOWING:
61006 case WindowBoundary::INVALID:
61007 throw InternalException("Unrecognized FROM in WindowExpression");
61008 }
61009
61010 string to;
61011 switch (entry.end) {
61012 case WindowBoundary::CURRENT_ROW_RANGE:
61013 if (entry.start != WindowBoundary::UNBOUNDED_PRECEDING) {
61014 to = "CURRENT ROW";
61015 units = "RANGE";
61016 }
61017 break;
61018 case WindowBoundary::CURRENT_ROW_ROWS:
61019 case WindowBoundary::CURRENT_ROW_GROUPS:
61020 to = "CURRENT ROW";
61021 units = ToUnits(entry.end, WindowBoundary::CURRENT_ROW_ROWS, WindowBoundary::CURRENT_ROW_RANGE,
61022 WindowBoundary::CURRENT_ROW_GROUPS);
61023 break;
61024 case WindowBoundary::UNBOUNDED_PRECEDING:
61025 to = "UNBOUNDED PRECEDING";
61026 break;
61027 case WindowBoundary::UNBOUNDED_FOLLOWING:
61028 to = "UNBOUNDED FOLLOWING";
61029 break;
61030 case WindowBoundary::EXPR_PRECEDING_ROWS:
61031 case WindowBoundary::EXPR_PRECEDING_RANGE:
61032 case WindowBoundary::EXPR_PRECEDING_GROUPS:
61033 to = entry.end_expr->ToString() + " PRECEDING";
61034 units = ToUnits(entry.end, WindowBoundary::EXPR_PRECEDING_ROWS, WindowBoundary::EXPR_PRECEDING_RANGE,
61035 WindowBoundary::EXPR_PRECEDING_GROUPS);
61036 break;
61037 case WindowBoundary::EXPR_FOLLOWING_ROWS:
61038 case WindowBoundary::EXPR_FOLLOWING_RANGE:
61039 case WindowBoundary::EXPR_FOLLOWING_GROUPS:
61040 to = entry.end_expr->ToString() + " FOLLOWING";
61041 units = ToUnits(entry.end, WindowBoundary::EXPR_FOLLOWING_ROWS, WindowBoundary::EXPR_FOLLOWING_RANGE,
61042 WindowBoundary::EXPR_FOLLOWING_GROUPS);
61043 break;
61044 case WindowBoundary::INVALID:
61045 throw InternalException("Unrecognized TO in WindowExpression");
61046 }
61047 if (entry.exclude_clause != WindowExcludeMode::NO_OTHER) {
61048 // if we have an explicit EXCLUDE we always need to fill in from/to
61049 if (from.empty()) {
61050 from = "UNBOUNDED PRECEDING";
61051 }
61052 if (to.empty()) {
61053 to = "CURRENT ROW";
61054 units = "RANGE";
61055 }
61056 }
61057
61058 if (!from.empty() || !to.empty()) {
61059 result += sep + units;
61060 }
61061 if (!from.empty() && !to.empty()) {
61062 result += " BETWEEN ";
61063 result += from;
61064 result += " AND ";
61065 result += to;
61066 } else if (!from.empty()) {
61067 result += " ";
61068 result += from;
61069 } else if (!to.empty()) {
61070 result += " ";
61071 result += to;
61072 }
61073
61074 if (entry.exclude_clause != WindowExcludeMode::NO_OTHER) {
61075 result += " EXCLUDE ";
61076 }
61077 switch (entry.exclude_clause) {
61078 case WindowExcludeMode::CURRENT_ROW:
61079 result += "CURRENT ROW";
61080 break;
61081 case WindowExcludeMode::GROUP:
61082 result += "GROUP";
61083 break;
61084 case WindowExcludeMode::TIES:
61085 result += "TIES";
61086 break;
61087 default:
61088 break;
61089 }
61090
61091 result += ")";
61092
61093 return result;
61094 }
static DUCKDB_API string Join(const vector< string > &input, const string &separator)
Join multiple strings into one string. Components are concatenated by the given separator.
string function_name
Name of the aggregate function.
Definition duckdb.cpp:60855
string schema
Schema of the aggregate function.
Definition duckdb.cpp:60853

Member Data Documentation

◆ arg_orders

vector<OrderByNode> duckdb::WindowExpression::arg_orders

The set of argument ordering clauses These are distinct from the frame ordering clauses e.g., the "x" in FIRST_VALUE(a ORDER BY x) OVER (PARTITION BY p ORDER BY s)


The documentation for this class was generated from the following file: