This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 501
/
limit_plan_node.h
126 lines (103 loc) · 2.68 KB
/
limit_plan_node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "catalog/schema.h"
#include "planner/plannodes/abstract_plan_node.h"
#include "planner/plannodes/plan_visitor.h"
namespace noisepage::planner {
/**
* Plan node for a limit operator
*/
class LimitPlanNode : public AbstractPlanNode {
public:
/**
* Builder for limit plan node
*/
class Builder : public AbstractPlanNode::Builder<Builder> {
public:
Builder() = default;
/**
* Don't allow builder to be copied or moved
*/
DISALLOW_COPY_AND_MOVE(Builder);
/**
* @param limit number of tuples to limit to
* @return object
*/
Builder &SetLimit(size_t limit) {
limit_ = limit;
return *this;
}
/**
* @param offset offset for where to limit from
* @return builder object
*/
Builder &SetOffset(size_t offset) {
offset_ = offset;
return *this;
}
/**
* Build the limit plan node
* @return plan node
*/
std::unique_ptr<LimitPlanNode> Build();
protected:
/**
* Limit for plan
*/
size_t limit_;
/**
* offset for plan
*/
size_t offset_;
};
private:
/**
* @param children child plan nodes
* @param output_schema Schema representing the structure of the output of this plan node
* @param limit number of tuples to limit to
* @param offset offset at which to limit from
* @param plan_node_id Plan node id
*/
LimitPlanNode(std::vector<std::unique_ptr<AbstractPlanNode>> &&children, std::unique_ptr<OutputSchema> output_schema,
size_t limit, size_t offset, plan_node_id_t plan_node_id);
public:
/**
* Constructor used for JSON serialization
*/
LimitPlanNode() = default;
DISALLOW_COPY_AND_MOVE(LimitPlanNode)
/**
* @return the type of this plan node
*/
PlanNodeType GetPlanNodeType() const override { return PlanNodeType::LIMIT; }
/**
* @return number to limit to
*/
size_t GetLimit() const { return limit_; }
/**
* @return offset for where to limit from
*/
size_t GetOffset() const { return offset_; }
/**
* @return the hashed value of this plan node
*/
common::hash_t Hash() const override;
bool operator==(const AbstractPlanNode &rhs) const override;
void Accept(common::ManagedPointer<PlanVisitor> v) const override { v->Visit(this); }
nlohmann::json ToJson() const override;
std::vector<std::unique_ptr<parser::AbstractExpression>> FromJson(const nlohmann::json &j) override;
private:
/**
* The limit
*/
size_t limit_;
/**
* The offset
*/
size_t offset_;
};
DEFINE_JSON_HEADER_DECLARATIONS(LimitPlanNode);
} // namespace noisepage::planner