1#include "duckdb/parser/query_node.hpp"
2#include "duckdb/planner/binder.hpp"
3#include "duckdb/planner/operator/logical_distinct.hpp"
4#include "duckdb/planner/operator/logical_limit.hpp"
5#include "duckdb/planner/operator/logical_order.hpp"
6
7using namespace duckdb;
8using namespace std;
9
10unique_ptr<LogicalOperator> Binder::VisitQueryNode(BoundQueryNode &node, unique_ptr<LogicalOperator> root) {
11 assert(root);
12 for (auto &mod : node.modifiers) {
13 switch (mod->type) {
14 case ResultModifierType::DISTINCT_MODIFIER: {
15 auto &bound = (BoundDistinctModifier &)*mod;
16 auto distinct = make_unique<LogicalDistinct>(move(bound.target_distincts));
17 distinct->AddChild(move(root));
18 root = move(distinct);
19 break;
20 }
21 case ResultModifierType::ORDER_MODIFIER: {
22 auto &bound = (BoundOrderModifier &)*mod;
23 auto order = make_unique<LogicalOrder>(move(bound.orders));
24 order->AddChild(move(root));
25 root = move(order);
26 break;
27 }
28 case ResultModifierType::LIMIT_MODIFIER: {
29 auto &bound = (BoundLimitModifier &)*mod;
30 auto limit = make_unique<LogicalLimit>(bound.limit, bound.offset);
31 limit->AddChild(move(root));
32 root = move(limit);
33 break;
34 }
35 default:
36 throw BinderException("Unimplemented modifier type!");
37 }
38 }
39 return root;
40}
41