1818//! Tests for the DataFusion SQL query planner that require functions from the
1919//! datafusion-functions crate.
2020
21+ use insta:: assert_snapshot;
2122use std:: any:: Any ;
2223use std:: collections:: HashMap ;
2324use std:: sync:: Arc ;
@@ -56,9 +57,14 @@ fn init() {
5657#[ test]
5758fn select_arrow_cast ( ) {
5859 let sql = "SELECT arrow_cast(1234, 'Float64') as f64, arrow_cast('foo', 'LargeUtf8') as large" ;
59- let expected = "Projection: Float64(1234) AS f64, LargeUtf8(\" foo\" ) AS large\
60- \n EmptyRelation";
61- quick_test ( sql, expected) ;
60+ let plan = test_sql ( sql) . unwrap ( ) ;
61+ assert_snapshot ! (
62+ plan,
63+ @r#"
64+ Projection: Float64(1234) AS f64, LargeUtf8("foo") AS large
65+ EmptyRelation
66+ "#
67+ ) ;
6268}
6369#[ test]
6470fn timestamp_nano_ts_none_predicates ( ) -> Result < ( ) > {
@@ -68,11 +74,15 @@ fn timestamp_nano_ts_none_predicates() -> Result<()> {
6874 // a scan should have the now()... predicate folded to a single
6975 // constant and compared to the column without a cast so it can be
7076 // pushed down / pruned
71- let expected =
72- "Projection: test.col_int32\
73- \n Filter: test.col_ts_nano_none < TimestampNanosecond(1666612093000000000, None)\
74- \n TableScan: test projection=[col_int32, col_ts_nano_none]";
75- quick_test ( sql, expected) ;
77+ let plan = test_sql ( sql) . unwrap ( ) ;
78+ assert_snapshot ! (
79+ plan,
80+ @r"
81+ Projection: test.col_int32
82+ Filter: test.col_ts_nano_none < TimestampNanosecond(1666612093000000000, None)
83+ TableScan: test projection=[col_int32, col_ts_nano_none]
84+ "
85+ ) ;
7686 Ok ( ( ) )
7787}
7888
@@ -84,21 +94,30 @@ fn timestamp_nano_ts_utc_predicates() {
8494 // a scan should have the now()... predicate folded to a single
8595 // constant and compared to the column without a cast so it can be
8696 // pushed down / pruned
87- let expected =
88- "Projection: test.col_int32\n Filter: test.col_ts_nano_utc < TimestampNanosecond(1666612093000000000, Some(\" +00:00\" ))\
89- \n TableScan: test projection=[col_int32, col_ts_nano_utc]";
90- quick_test ( sql, expected) ;
97+ let plan = test_sql ( sql) . unwrap ( ) ;
98+ assert_snapshot ! (
99+ plan,
100+ @r#"
101+ Projection: test.col_int32
102+ Filter: test.col_ts_nano_utc < TimestampNanosecond(1666612093000000000, Some("+00:00"))
103+ TableScan: test projection=[col_int32, col_ts_nano_utc]
104+ "#
105+ ) ;
91106}
92107
93108#[ test]
94109fn concat_literals ( ) -> Result < ( ) > {
95110 let sql = "SELECT concat(true, col_int32, false, null, 'hello', col_utf8, 12, 3.4) \
96111 AS col
97112 FROM test" ;
98- let expected =
99- "Projection: concat(Utf8(\" true\" ), CAST(test.col_int32 AS Utf8), Utf8(\" falsehello\" ), test.col_utf8, Utf8(\" 123.4\" )) AS col\
100- \n TableScan: test projection=[col_int32, col_utf8]";
101- quick_test ( sql, expected) ;
113+ let plan = test_sql ( sql) . unwrap ( ) ;
114+ assert_snapshot ! (
115+ plan,
116+ @r#"
117+ Projection: concat(Utf8("true"), CAST(test.col_int32 AS Utf8), Utf8("falsehello"), test.col_utf8, Utf8("123.4")) AS col
118+ TableScan: test projection=[col_int32, col_utf8]
119+ "#
120+ ) ;
102121 Ok ( ( ) )
103122}
104123
@@ -107,16 +126,15 @@ fn concat_ws_literals() -> Result<()> {
107126 let sql = "SELECT concat_ws('-', true, col_int32, false, null, 'hello', col_utf8, 12, '', 3.4) \
108127 AS col
109128 FROM test" ;
110- let expected =
111- "Projection: concat_ws(Utf8(\" -\" ), Utf8(\" true\" ), CAST(test.col_int32 AS Utf8), Utf8(\" false-hello\" ), test.col_utf8, Utf8(\" 12--3.4\" )) AS col\
112- \n TableScan: test projection=[col_int32, col_utf8]";
113- quick_test ( sql, expected) ;
114- Ok ( ( ) )
115- }
116-
117- fn quick_test ( sql : & str , expected_plan : & str ) {
118129 let plan = test_sql ( sql) . unwrap ( ) ;
119- assert_eq ! ( expected_plan, format!( "{plan}" ) ) ;
130+ assert_snapshot ! (
131+ plan,
132+ @r#"
133+ Projection: concat_ws(Utf8("-"), Utf8("true"), CAST(test.col_int32 AS Utf8), Utf8("false-hello"), test.col_utf8, Utf8("12--3.4")) AS col
134+ TableScan: test projection=[col_int32, col_utf8]
135+ "#
136+ ) ;
137+ Ok ( ( ) )
120138}
121139
122140fn test_sql ( sql : & str ) -> Result < LogicalPlan > {
0 commit comments