1#include "duckdb/main/relation/order_relation.hpp"
2#include "duckdb/main/client_context.hpp"
3#include "duckdb/parser/query_node.hpp"
4
5namespace duckdb {
6
7OrderRelation::OrderRelation(shared_ptr<Relation> child_p, vector<OrderByNode> orders)
8 : Relation(child_p->context, RelationType::ORDER_RELATION), orders(move(orders)), child(move(child_p)) {
9 // bind the expressions
10 vector<ColumnDefinition> dummy_columns;
11 context.TryBindRelation(*this, dummy_columns);
12}
13
14unique_ptr<QueryNode> OrderRelation::GetQueryNode() {
15 auto child_node = child->GetQueryNode();
16 auto order_node = make_unique<OrderModifier>();
17 for (idx_t i = 0; i < orders.size(); i++) {
18 OrderByNode node;
19 node.expression = orders[i].expression->Copy();
20 node.type = orders[i].type;
21 order_node->orders.push_back(move(node));
22 }
23 child_node->modifiers.push_back(move(order_node));
24 return child_node;
25}
26
27string OrderRelation::GetAlias() {
28 return child->GetAlias();
29}
30
31const vector<ColumnDefinition> &OrderRelation::Columns() {
32 return child->Columns();
33}
34
35string OrderRelation::ToString(idx_t depth) {
36 string str = RenderWhitespace(depth) + "Order [";
37 for (idx_t i = 0; i < orders.size(); i++) {
38 if (i != 0) {
39 str += ", ";
40 }
41 str += orders[i].expression->ToString() + (orders[i].type == OrderType::ASCENDING ? " ASC" : " DESC");
42 }
43 str += "]\n";
44 return str + child->ToString(depth + 1);
45}
46
47} // namespace duckdb
48