1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | TEST_CASE("Test that aliases work properly in renaming columns" , "[alias]" ) { |
8 | unique_ptr<QueryResult> result; |
9 | DuckDB db(nullptr); |
10 | Connection con(db); |
11 | con.EnableQueryVerification(); |
12 | |
13 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i INTEGER);" )); |
14 | REQUIRE_NO_FAIL(con.Query("INSERT INTO integers VALUES (1), (2), (3), (NULL)" )); |
15 | |
16 | result = con.Query("SELECT i % 2 AS p, SUM(i) AS sum_i FROM integers GROUP BY p ORDER BY 1" ); |
17 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 0, 1})); |
18 | REQUIRE(CHECK_COLUMN(result, 1, {Value(), 2, 4})); |
19 | REQUIRE(result->names[0] == "p" ); |
20 | REQUIRE(result->names[1] == "sum_i" ); |
21 | |
22 | result = con.Query("SELECT i + 1 + 1 + 1 AS k, abs(i) AS l FROM integers WHERE i=1 ORDER BY 1" ); |
23 | REQUIRE(CHECK_COLUMN(result, 0, {4})); |
24 | REQUIRE(CHECK_COLUMN(result, 1, {1})); |
25 | REQUIRE(result->names[0] == "k" ); |
26 | REQUIRE(result->names[1] == "l" ); |
27 | |
28 | result = con.Query("SELECT i AS k, i IN (1) AS l, i >= 10 AS m, 1=0 AS n FROM integers WHERE i=1 ORDER BY 1" ); |
29 | REQUIRE(CHECK_COLUMN(result, 0, {1})); |
30 | REQUIRE(CHECK_COLUMN(result, 1, {true})); |
31 | REQUIRE(CHECK_COLUMN(result, 2, {false})); |
32 | REQUIRE(CHECK_COLUMN(result, 3, {false})); |
33 | REQUIRE(result->names[0] == "k" ); |
34 | REQUIRE(result->names[1] == "l" ); |
35 | REQUIRE(result->names[2] == "m" ); |
36 | REQUIRE(result->names[3] == "n" ); |
37 | |
38 | result = |
39 | con.Query("SELECT CASE WHEN i=1 THEN 19 ELSE 0 END AS k, i::VARCHAR AS l FROM integers WHERE i=1 ORDER BY 1" ); |
40 | REQUIRE(CHECK_COLUMN(result, 0, {19})); |
41 | REQUIRE(CHECK_COLUMN(result, 1, {"1" })); |
42 | REQUIRE(result->names[0] == "k" ); |
43 | REQUIRE(result->names[1] == "l" ); |
44 | } |
45 | |