1 | #include "duckdb/parser/expression/constant_expression.hpp" |
---|---|
2 | #include "duckdb/parser/statement/select_statement.hpp" |
3 | #include "duckdb/parser/transformer.hpp" |
4 | |
5 | using namespace duckdb; |
6 | using namespace std; |
7 | |
8 | bool Transformer::TransformOrderBy(PGList *order, vector<OrderByNode> &result) { |
9 | if (!order) { |
10 | return false; |
11 | } |
12 | |
13 | for (auto node = order->head; node != nullptr; node = node->next) { |
14 | auto temp = reinterpret_cast<PGNode *>(node->data.ptr_value); |
15 | if (temp->type == T_PGSortBy) { |
16 | OrderByNode ordernode; |
17 | auto sort = reinterpret_cast<PGSortBy *>(temp); |
18 | auto target = sort->node; |
19 | if (sort->sortby_dir == PG_SORTBY_ASC || sort->sortby_dir == PG_SORTBY_DEFAULT) { |
20 | ordernode.type = OrderType::ASCENDING; |
21 | } else if (sort->sortby_dir == PG_SORTBY_DESC) { |
22 | ordernode.type = OrderType::DESCENDING; |
23 | } else { |
24 | throw NotImplementedException("Unimplemented order by type"); |
25 | } |
26 | ordernode.expression = TransformExpression(target); |
27 | result.push_back(OrderByNode(ordernode.type, move(ordernode.expression))); |
28 | } else { |
29 | throw NotImplementedException("ORDER BY list member type %d\n", temp->type); |
30 | } |
31 | } |
32 | return true; |
33 | } |
34 |