1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/planner/expression/bound_window_expression.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/parser/expression/window_expression.hpp"
12#include "duckdb/function/function.hpp"
13#include "duckdb/planner/bound_query_node.hpp"
14#include "duckdb/planner/expression.hpp"
15
16namespace duckdb {
17class AggregateFunction;
18
19class BoundWindowExpression : public Expression {
20public:
21 static constexpr const ExpressionClass TYPE = ExpressionClass::BOUND_WINDOW;
22
23public:
24 BoundWindowExpression(ExpressionType type, LogicalType return_type, unique_ptr<AggregateFunction> aggregate,
25 unique_ptr<FunctionData> bind_info);
26
27 //! The bound aggregate function
28 unique_ptr<AggregateFunction> aggregate;
29 //! The bound function info
30 unique_ptr<FunctionData> bind_info;
31 //! The child expressions of the main window function
32 vector<unique_ptr<Expression>> children;
33 //! The set of expressions to partition by
34 vector<unique_ptr<Expression>> partitions;
35 //! Statistics belonging to the partitions expressions
36 vector<unique_ptr<BaseStatistics>> partitions_stats;
37 //! The set of ordering clauses
38 vector<BoundOrderByNode> orders;
39 //! Expression representing a filter, only used for aggregates
40 unique_ptr<Expression> filter_expr;
41 //! True to ignore NULL values
42 bool ignore_nulls;
43 //! The window boundaries
44 WindowBoundary start = WindowBoundary::INVALID;
45 WindowBoundary end = WindowBoundary::INVALID;
46
47 unique_ptr<Expression> start_expr;
48 unique_ptr<Expression> end_expr;
49 //! Offset and default expressions for WINDOW_LEAD and WINDOW_LAG functions
50 unique_ptr<Expression> offset_expr;
51 unique_ptr<Expression> default_expr;
52
53public:
54 bool IsWindow() const override {
55 return true;
56 }
57 bool IsFoldable() const override {
58 return false;
59 }
60
61 string ToString() const override;
62
63 bool KeysAreCompatible(const BoundWindowExpression &other) const;
64 bool Equals(const BaseExpression &other) const override;
65
66 unique_ptr<Expression> Copy() override;
67
68 void Serialize(FieldWriter &writer) const override;
69 static unique_ptr<Expression> Deserialize(ExpressionDeserializationState &state, FieldReader &reader);
70};
71} // namespace duckdb
72