@@ -40,7 +40,7 @@ use datafusion::{
4040 prelude:: SessionContext ,
4141 scalar:: ScalarValue ,
4242} ;
43- use datafusion_common:: { cast:: as_primitive_array, DataFusionError } ;
43+ use datafusion_common:: { assert_contains , cast:: as_primitive_array, DataFusionError } ;
4444
4545/// Test to show the contents of the setup
4646#[ tokio:: test]
@@ -58,7 +58,7 @@ async fn test_setup() {
5858 "| 5.0 | 1970-01-01T00:00:00.000005 |" ,
5959 "+-------+----------------------------+" ,
6060 ] ;
61- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
61+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
6262}
6363
6464/// Basic user defined aggregate
@@ -74,7 +74,7 @@ async fn test_udaf() {
7474 "| 1970-01-01T00:00:00.000019 |" ,
7575 "+----------------------------+" ,
7676 ] ;
77- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
77+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
7878 // normal aggregates call update_batch
7979 assert ! ( test_state. update_batch( ) ) ;
8080 assert ! ( !test_state. retract_batch( ) ) ;
@@ -96,7 +96,7 @@ async fn test_udaf_as_window() {
9696 "| 1970-01-01T00:00:00.000019 |" ,
9797 "+----------------------------+" ,
9898 ] ;
99- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
99+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
100100 // aggregate over the entire window function call update_batch
101101 assert ! ( test_state. update_batch( ) ) ;
102102 assert ! ( !test_state. retract_batch( ) ) ;
@@ -118,35 +118,23 @@ async fn test_udaf_as_window_with_frame() {
118118 "| 1970-01-01T00:00:00.000010 |" ,
119119 "+----------------------------+" ,
120120 ] ;
121- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
121+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
122122 // user defined aggregates with window frame should be calling retract batch
123123 assert ! ( test_state. update_batch( ) ) ;
124124 assert ! ( test_state. retract_batch( ) ) ;
125125}
126126
127127/// Ensure that User defined aggregate used as a window function with a window
128- /// frame, but that does not implement retract_batch, does not error
128+ /// frame, but that does not implement retract_batch, returns an error
129129#[ tokio:: test]
130130async fn test_udaf_as_window_with_frame_without_retract_batch ( ) {
131131 let test_state = Arc :: new ( TestState :: new ( ) . with_error_on_retract_batch ( ) ) ;
132132
133- let TestContext { ctx, test_state } = TestContext :: new_with_test_state ( test_state) ;
133+ let TestContext { ctx, test_state : _ } = TestContext :: new_with_test_state ( test_state) ;
134134 let sql = "SELECT time_sum(time) OVER(ORDER BY time ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as time_sum from t" ;
135- // TODO: It is not clear why this is a different value than when retract batch is used
136- let expected = vec ! [
137- "+----------------------------+" ,
138- "| time_sum |" ,
139- "+----------------------------+" ,
140- "| 1970-01-01T00:00:00.000005 |" ,
141- "| 1970-01-01T00:00:00.000009 |" ,
142- "| 1970-01-01T00:00:00.000014 |" ,
143- "| 1970-01-01T00:00:00.000019 |" ,
144- "| 1970-01-01T00:00:00.000019 |" ,
145- "+----------------------------+" ,
146- ] ;
147- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
148- assert ! ( test_state. update_batch( ) ) ;
149- assert ! ( !test_state. retract_batch( ) ) ;
135+ // Note if this query ever does start working
136+ let err = execute ( & ctx, sql) . await . unwrap_err ( ) ;
137+ assert_contains ! ( err. to_string( ) , "This feature is not implemented: Aggregate can not be used as a sliding accumulator because `retract_batch` is not implemented: AggregateUDF { name: \" time_sum\" " ) ;
150138}
151139
152140/// Basic query for with a udaf returning a structure
@@ -161,7 +149,7 @@ async fn test_udaf_returning_struct() {
161149 "| {value: 2.0, time: 1970-01-01T00:00:00.000002} |" ,
162150 "+------------------------------------------------+" ,
163151 ] ;
164- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
152+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
165153}
166154
167155/// Demonstrate extracting the fields from a structure using a subquery
@@ -176,11 +164,11 @@ async fn test_udaf_returning_struct_subquery() {
176164 "| 2.0 | 1970-01-01T00:00:00.000002 |" ,
177165 "+-----------------+----------------------------+" ,
178166 ] ;
179- assert_batches_eq ! ( expected, & execute( & ctx, sql) . await ) ;
167+ assert_batches_eq ! ( expected, & execute( & ctx, sql) . await . unwrap ( ) ) ;
180168}
181169
182- async fn execute ( ctx : & SessionContext , sql : & str ) -> Vec < RecordBatch > {
183- ctx. sql ( sql) . await . unwrap ( ) . collect ( ) . await . unwrap ( )
170+ async fn execute ( ctx : & SessionContext , sql : & str ) -> Result < Vec < RecordBatch > > {
171+ ctx. sql ( sql) . await ? . collect ( ) . await
184172}
185173
186174/// Returns an context with a table "t" and the "first" and "time_sum"
0 commit comments