From ba563ad8ad1f58dcb2182531bf92591a3a6d78ac Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 2 Feb 2023 13:31:00 -0500 Subject: [PATCH] Add more test coverage --- datafusion/sql/tests/integration_test.rs | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/datafusion/sql/tests/integration_test.rs b/datafusion/sql/tests/integration_test.rs index 600b78457045..991dbe89efd4 100644 --- a/datafusion/sql/tests/integration_test.rs +++ b/datafusion/sql/tests/integration_test.rs @@ -2349,6 +2349,8 @@ fn select_multibyte_column() { #[test] fn select_groupby_orderby() { + // ensure that references are correctly resolved in the order by clause + // see https://github.com/apache/arrow-datafusion/issues/4854 let sql = r#"SELECT avg(age) AS "value", date_trunc('month', birth_date) AS "birth_date" @@ -2361,6 +2363,30 @@ fn select_groupby_orderby() { \n Aggregate: groupBy=[[person.birth_date]], aggr=[[AVG(person.age)]]\ \n TableScan: person"; quick_test(sql, expected); + + // Use fully qualified `person.birth_date` as argument to date_trunc, plan should be the same + let sql = r#"SELECT + avg(age) AS "value", + date_trunc('month', person.birth_date) AS "birth_date" + FROM person GROUP BY birth_date ORDER BY birth_date; +"#; + quick_test(sql, expected); + + // Use fully qualified `person.birth_date` as group by, plan should be the same + let sql = r#"SELECT + avg(age) AS "value", + date_trunc('month', birth_date) AS "birth_date" + FROM person GROUP BY person.birth_date ORDER BY birth_date; +"#; + quick_test(sql, expected); + + // Use fully qualified `person.birth_date` in both group and date_trunc, plan should be the same + let sql = r#"SELECT + avg(age) AS "value", + date_trunc('month', person.birth_date) AS "birth_date" + FROM person GROUP BY person.birth_date ORDER BY birth_date; +"#; + quick_test(sql, expected); } fn logical_plan(sql: &str) -> Result {