1#include "duckdb/main/relation/limit_relation.hpp"
2#include "duckdb/parser/query_node/select_node.hpp"
3#include "duckdb/parser/query_node.hpp"
4#include "duckdb/parser/expression/constant_expression.hpp"
5
6namespace duckdb {
7
8LimitRelation::LimitRelation(shared_ptr<Relation> child_p, int64_t limit, int64_t offset)
9 : Relation(child_p->context, RelationType::PROJECTION_RELATION), limit(limit), offset(offset), child(move(child_p)) {
10}
11
12unique_ptr<QueryNode> LimitRelation::GetQueryNode() {
13 auto child_node = child->GetQueryNode();
14 auto limit_node = make_unique<LimitModifier>();
15 if (limit >= 0) {
16 limit_node->limit = make_unique<ConstantExpression>(SQLType::BIGINT, Value::BIGINT(limit));
17 }
18 if (offset > 0) {
19 limit_node->offset = make_unique<ConstantExpression>(SQLType::BIGINT, Value::BIGINT(offset));
20 }
21
22 child_node->modifiers.push_back(move(limit_node));
23 return child_node;
24}
25
26string LimitRelation::GetAlias() {
27 return child->GetAlias();
28}
29
30const vector<ColumnDefinition> &LimitRelation::Columns() {
31 return child->Columns();
32}
33
34string LimitRelation::ToString(idx_t depth) {
35 string str = RenderWhitespace(depth) + "Limit " + std::to_string(limit);
36 if (offset > 0) {
37 str += " Offset " + std::to_string(offset);
38 }
39 str += "\n";
40 return str + child->ToString(depth + 1);
41}
42
43} // namespace duckdb
44