Skip to content

Commit 345d4da

Browse files
committed
resolve comments
1 parent b8b8d9e commit 345d4da

File tree

1 file changed

+48
-78
lines changed

1 file changed

+48
-78
lines changed

datafusion/sql/tests/sql_integration.rs

Lines changed: 48 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,11 @@ fn select_simple_aggregate_and_nested_groupby_column() {
17951795

17961796
#[test]
17971797
fn select_aggregate_compounded_with_groupby_column() {
1798-
let plan =
1799-
generate_logical_plan("SELECT age + MIN(salary), age FROM person GROUP BY age");
1798+
let plan = generate_logical_plan("SELECT age + MIN(salary) FROM person GROUP BY age");
18001799
assert_snapshot!(
18011800
plan,
18021801
@r#"
1803-
Projection: person.age + min(person.salary), person.age
1802+
Projection: person.age + min(person.salary)
18041803
Aggregate: groupBy=[[person.age]], aggr=[[min(person.salary)]]
18051804
TableScan: person
18061805
"#
@@ -3057,79 +3056,51 @@ Projection: person.😀
30573056
fn select_groupby_orderby() {
30583057
// ensure that references are correctly resolved in the order by clause
30593058
// see https://github.com/apache/datafusion/issues/4854
3060-
let sql = r#"SELECT
3061-
avg(age) AS "value",
3062-
date_trunc('month', birth_date) AS "birth_date"
3063-
FROM person GROUP BY birth_date ORDER BY birth_date;
3064-
"#;
3065-
3066-
let plan = generate_logical_plan(sql);
3067-
assert_snapshot!(
3068-
plan,
3069-
// expect that this is not an ambiguous reference
3070-
@r#"
3071-
Sort: birth_date ASC NULLS LAST
3072-
Projection: avg(person.age) AS value, date_trunc(Utf8("month"), person.birth_date) AS birth_date
3073-
Aggregate: groupBy=[[person.birth_date]], aggr=[[avg(person.age)]]
3074-
TableScan: person
3075-
"#
3076-
);
3077-
3078-
// Use fully qualified `person.birth_date` as argument to date_trunc, plan should be the same
3079-
let sql = r#"SELECT
3080-
avg(age) AS "value",
3081-
date_trunc('month', person.birth_date) AS "birth_date"
3082-
FROM person GROUP BY birth_date ORDER BY birth_date;
3083-
"#;
3084-
let plan = generate_logical_plan(sql);
3085-
assert_snapshot!(
3086-
plan,
3087-
// expect that this is not an ambiguous reference
3088-
@r#"
3089-
Sort: birth_date ASC NULLS LAST
3090-
Projection: avg(person.age) AS value, date_trunc(Utf8("month"), person.birth_date) AS birth_date
3091-
Aggregate: groupBy=[[person.birth_date]], aggr=[[avg(person.age)]]
3092-
TableScan: person
3093-
"#
3094-
);
3095-
3096-
// Use fully qualified `person.birth_date` as group by, plan should be the same
3097-
let sql = r#"SELECT
3098-
avg(age) AS "value",
3099-
date_trunc('month', birth_date) AS "birth_date"
3100-
FROM person GROUP BY person.birth_date ORDER BY birth_date;
3101-
"#;
3102-
3103-
let plan = generate_logical_plan(sql);
3104-
assert_snapshot!(
3105-
plan,
3106-
// expect that this is not an ambiguous reference
3107-
@r#"
3108-
Sort: birth_date ASC NULLS LAST
3109-
Projection: avg(person.age) AS value, date_trunc(Utf8("month"), person.birth_date) AS birth_date
3110-
Aggregate: groupBy=[[person.birth_date]], aggr=[[avg(person.age)]]
3111-
TableScan: person
3112-
"#
3113-
);
31143059

3115-
// Use fully qualified `person.birth_date` in both group and date_trunc, plan should be the same
3116-
let sql = r#"SELECT
3117-
avg(age) AS "value",
3118-
date_trunc('month', person.birth_date) AS "birth_date"
3119-
FROM person GROUP BY person.birth_date ORDER BY birth_date;
3120-
"#;
3121-
3122-
let plan = generate_logical_plan(sql);
3123-
assert_snapshot!(
3124-
plan,
3125-
// expect that this is not an ambiguous reference
3126-
@r#"
3127-
Sort: birth_date ASC NULLS LAST
3128-
Projection: avg(person.age) AS value, date_trunc(Utf8("month"), person.birth_date) AS birth_date
3129-
Aggregate: groupBy=[[person.birth_date]], aggr=[[avg(person.age)]]
3130-
TableScan: person
3131-
"#
3132-
);
3060+
let sqls = vec![
3061+
r#"
3062+
SELECT
3063+
avg(age) AS "value",
3064+
date_trunc('month', birth_date) AS "birth_date"
3065+
FROM person GROUP BY birth_date ORDER BY birth_date;
3066+
"#,
3067+
// Use fully qualified `person.birth_date` as argument to date_trunc, plan should be the same
3068+
r#"
3069+
SELECT
3070+
avg(age) AS "value",
3071+
date_trunc('month', person.birth_date) AS "birth_date"
3072+
FROM person GROUP BY birth_date ORDER BY birth_date;
3073+
"#,
3074+
// Use fully qualified `person.birth_date` as group by, plan should be the same
3075+
r#"
3076+
SELECT
3077+
avg(age) AS "value",
3078+
date_trunc('month', birth_date) AS "birth_date"
3079+
FROM person GROUP BY person.birth_date ORDER BY birth_date;
3080+
"#,
3081+
// Use fully qualified `person.birth_date` in both group and date_trunc, plan should be the same
3082+
r#"
3083+
SELECT
3084+
avg(age) AS "value",
3085+
date_trunc('month', person.birth_date) AS "birth_date"
3086+
FROM person GROUP BY person.birth_date ORDER BY birth_date;
3087+
"#,
3088+
];
3089+
for sql in sqls {
3090+
let plan = generate_logical_plan(sql);
3091+
allow_duplicates! {
3092+
assert_snapshot!(
3093+
plan,
3094+
// expect that this is not an ambiguous reference
3095+
@r#"
3096+
Sort: birth_date ASC NULLS LAST
3097+
Projection: avg(person.age) AS value, date_trunc(Utf8("month"), person.birth_date) AS birth_date
3098+
Aggregate: groupBy=[[person.birth_date]], aggr=[[avg(person.age)]]
3099+
TableScan: person
3100+
"#
3101+
);
3102+
}
3103+
}
31333104

31343105
// Use columnized `avg(age)` in the order by
31353106
let sql = r#"SELECT
@@ -4986,13 +4957,12 @@ Projection: orders.order_id, max(orders.qty) PARTITION BY [orders.order_id] ROWS
49864957

49874958
#[test]
49884959
fn test_parse_escaped_string_literal_value() {
4989-
let sql = "SELECT character_length('\r\n') AS len";
4960+
let sql = r"SELECT character_length('\r\n') AS len";
49904961
let plan = generate_logical_plan(sql);
49914962
assert_snapshot!(
49924963
plan,
49934964
@r#"
4994-
Projection: character_length(Utf8("
4995-
")) AS len
4965+
Projection: character_length(Utf8("\r\n")) AS len
49964966
EmptyRelation
49974967
"#
49984968
);

0 commit comments

Comments
 (0)