18
18
//! Execution plan for reading line-delimited Avro files
19
19
#[ cfg( feature = "avro" ) ]
20
20
use crate :: avro_to_arrow;
21
- use crate :: error:: { DataFusionError , Result } ;
21
+ use crate :: error:: Result ;
22
22
use crate :: physical_plan:: expressions:: PhysicalSortExpr ;
23
23
use crate :: physical_plan:: {
24
24
DisplayFormatType , ExecutionPlan , Partitioning , SendableRecordBatchStream , Statistics ,
@@ -98,7 +98,7 @@ impl ExecutionPlan for AvroExec {
98
98
_partition : usize ,
99
99
_context : Arc < TaskContext > ,
100
100
) -> Result < SendableRecordBatchStream > {
101
- Err ( DataFusionError :: NotImplemented (
101
+ Err ( crate :: error :: DataFusionError :: NotImplemented (
102
102
"Cannot execute avro plan without avro feature enabled" . to_string ( ) ,
103
103
) )
104
104
}
@@ -165,17 +165,17 @@ impl ExecutionPlan for AvroExec {
165
165
#[ cfg( test) ]
166
166
#[ cfg( feature = "avro" ) ]
167
167
mod tests {
168
- use crate :: datasource:: object_store:: local:: {
169
- local_object_reader_stream, LocalFileSystem ,
170
- } ;
171
168
use crate :: datasource:: {
172
169
file_format:: { avro:: AvroFormat , FileFormat } ,
173
170
listing:: local_unpartitioned_file,
174
171
} ;
172
+ use crate :: prelude:: SessionContext ;
175
173
use crate :: scalar:: ScalarValue ;
176
174
use arrow:: datatypes:: { DataType , Field , Schema } ;
175
+ use datafusion_data_access:: object_store:: local:: {
176
+ local_object_reader_stream, LocalFileSystem ,
177
+ } ;
177
178
use futures:: StreamExt ;
178
- use sqlparser:: ast:: ObjectType :: Schema ;
179
179
180
180
use super :: * ;
181
181
@@ -196,7 +196,11 @@ mod tests {
196
196
} ) ;
197
197
assert_eq ! ( avro_exec. output_partitioning( ) . partition_count( ) , 1 ) ;
198
198
199
- let mut results = avro_exec. execute ( 0 ) . await . expect ( "plan execution failed" ) ;
199
+ let ctx = SessionContext :: new ( ) ;
200
+ let mut results = avro_exec
201
+ . execute ( 0 , ctx. task_ctx ( ) )
202
+ . expect ( "plan execution failed" ) ;
203
+
200
204
let batch = results
201
205
. next ( )
202
206
. await
@@ -237,27 +241,32 @@ mod tests {
237
241
let testdata = crate :: test_util:: arrow_test_data ( ) ;
238
242
let filename = format ! ( "{}/avro/alltypes_plain.avro" , testdata) ;
239
243
let actual_schema = AvroFormat { }
240
- . infer_schema ( local_object_reader_stream ( vec ! [ filename] ) )
244
+ . infer_schema ( local_object_reader_stream ( vec ! [ filename. clone ( ) ] ) )
241
245
. await ?;
242
246
243
247
let mut fields = actual_schema. fields ( ) . clone ( ) ;
244
248
fields. push ( Field :: new ( "missing_col" , DataType :: Int32 , true ) ) ;
245
249
246
250
let file_schema = Arc :: new ( Schema :: new ( fields) ) ;
251
+ // Include the missing column in the projection
252
+ let projection = Some ( vec ! [ 0 , 1 , 2 , actual_schema. fields( ) . len( ) ] ) ;
247
253
248
254
let avro_exec = AvroExec :: new ( FileScanConfig {
249
255
object_store : Arc :: new ( LocalFileSystem { } ) ,
250
256
file_groups : vec ! [ vec![ local_unpartitioned_file( filename. clone( ) ) ] ] ,
251
257
file_schema,
252
258
statistics : Statistics :: default ( ) ,
253
- // Include the missing column in the projection
254
- projection : Some ( vec ! [ 0 , 1 , 2 , file_schema. fields( ) . len( ) ] ) ,
259
+ projection,
255
260
limit : None ,
256
261
table_partition_cols : vec ! [ ] ,
257
262
} ) ;
258
263
assert_eq ! ( avro_exec. output_partitioning( ) . partition_count( ) , 1 ) ;
259
264
260
- let mut results = avro_exec. execute ( 0 ) . await . expect ( "plan execution failed" ) ;
265
+ let ctx = SessionContext :: new ( ) ;
266
+ let mut results = avro_exec
267
+ . execute ( 0 , ctx. task_ctx ( ) )
268
+ . expect ( "plan execution failed" ) ;
269
+
261
270
let batch = results
262
271
. next ( )
263
272
. await
@@ -310,14 +319,18 @@ mod tests {
310
319
projection : Some ( vec ! [ 0 , 1 , file_schema. fields( ) . len( ) , 2 ] ) ,
311
320
object_store : Arc :: new ( LocalFileSystem { } ) ,
312
321
file_groups : vec ! [ vec![ partitioned_file] ] ,
313
- file_schema : file_schema ,
322
+ file_schema,
314
323
statistics : Statistics :: default ( ) ,
315
324
limit : None ,
316
325
table_partition_cols : vec ! [ "date" . to_owned( ) ] ,
317
326
} ) ;
318
327
assert_eq ! ( avro_exec. output_partitioning( ) . partition_count( ) , 1 ) ;
319
328
320
- let mut results = avro_exec. execute ( 0 ) . await . expect ( "plan execution failed" ) ;
329
+ let ctx = SessionContext :: new ( ) ;
330
+ let mut results = avro_exec
331
+ . execute ( 0 , ctx. task_ctx ( ) )
332
+ . expect ( "plan execution failed" ) ;
333
+
321
334
let batch = results
322
335
. next ( )
323
336
. await
0 commit comments