1 | #include "catch.hpp" |
2 | #include "expression_helper.hpp" |
3 | #include "test_helpers.hpp" |
4 | |
5 | using namespace duckdb; |
6 | using namespace std; |
7 | |
8 | TEST_CASE("Test projection bindings for ORDER BY" , "[projection-binding-order-by]" ) { |
9 | ExpressionHelper helper; |
10 | using Op = LogicalOperatorType; |
11 | |
12 | auto projection_matches = [&](string query, vector<LogicalOperatorType> path, size_t count) -> bool { |
13 | auto plan = helper.ParseLogicalTree(query); |
14 | for (auto type : path) { |
15 | if (plan->type != type) |
16 | return false; |
17 | if (plan->children.size() == 0) |
18 | return false; |
19 | plan = move(plan->children[0]); |
20 | } |
21 | return (plan->type == Op::PROJECTION && plan->expressions.size() == count); |
22 | }; |
23 | |
24 | auto &con = helper.con; |
25 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE a (i INTEGER, j INTEGER)" )); |
26 | |
27 | REQUIRE(projection_matches("SELECT i FROM a ORDER BY i" , {Op::ORDER_BY}, 1)); |
28 | REQUIRE(projection_matches("SELECT a.i FROM a ORDER BY i" , {Op::ORDER_BY}, 1)); |
29 | REQUIRE(projection_matches("SELECT i FROM a ORDER BY a.i" , {Op::ORDER_BY}, 1)); |
30 | REQUIRE(projection_matches("SELECT i AS k FROM a ORDER BY i" , {Op::ORDER_BY}, 1)); |
31 | |
32 | con.Query("DROP TABLE a" ); |
33 | } |
34 | |