@@ -28,6 +28,7 @@ use object_store::{GetResult, ObjectMeta, ObjectStore};
28
28
use super :: FileFormat ;
29
29
use crate :: avro_to_arrow:: read_avro_schema_from_reader;
30
30
use crate :: error:: Result ;
31
+ use crate :: execution:: context:: SessionState ;
31
32
use crate :: logical_expr:: Expr ;
32
33
use crate :: physical_plan:: file_format:: { AvroExec , FileScanConfig } ;
33
34
use crate :: physical_plan:: ExecutionPlan ;
@@ -47,6 +48,7 @@ impl FileFormat for AvroFormat {
47
48
48
49
async fn infer_schema (
49
50
& self ,
51
+ _ctx : & SessionState ,
50
52
store : & Arc < dyn ObjectStore > ,
51
53
objects : & [ ObjectMeta ] ,
52
54
) -> Result < SchemaRef > {
@@ -68,6 +70,7 @@ impl FileFormat for AvroFormat {
68
70
69
71
async fn infer_stats (
70
72
& self ,
73
+ _ctx : & SessionState ,
71
74
_store : & Arc < dyn ObjectStore > ,
72
75
_table_schema : SchemaRef ,
73
76
_object : & ObjectMeta ,
@@ -77,6 +80,7 @@ impl FileFormat for AvroFormat {
77
80
78
81
async fn create_physical_plan (
79
82
& self ,
83
+ _ctx : & SessionState ,
80
84
conf : FileScanConfig ,
81
85
_filters : & [ Expr ] ,
82
86
) -> Result < Arc < dyn ExecutionPlan > > {
@@ -101,10 +105,11 @@ mod tests {
101
105
#[ tokio:: test]
102
106
async fn read_small_batches ( ) -> Result < ( ) > {
103
107
let config = SessionConfig :: new ( ) . with_batch_size ( 2 ) ;
104
- let ctx = SessionContext :: with_config ( config) ;
108
+ let session_ctx = SessionContext :: with_config ( config) ;
109
+ let ctx = session_ctx. state ( ) ;
105
110
let task_ctx = ctx. task_ctx ( ) ;
106
111
let projection = None ;
107
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
112
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
108
113
let stream = exec. execute ( 0 , task_ctx) ?;
109
114
110
115
let tt_batches = stream
@@ -124,9 +129,10 @@ mod tests {
124
129
#[ tokio:: test]
125
130
async fn read_limit ( ) -> Result < ( ) > {
126
131
let session_ctx = SessionContext :: new ( ) ;
127
- let task_ctx = session_ctx. task_ctx ( ) ;
132
+ let ctx = session_ctx. state ( ) ;
133
+ let task_ctx = ctx. task_ctx ( ) ;
128
134
let projection = None ;
129
- let exec = get_exec ( "alltypes_plain.avro" , projection, Some ( 1 ) ) . await ?;
135
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, Some ( 1 ) ) . await ?;
130
136
let batches = collect ( exec, task_ctx) . await ?;
131
137
assert_eq ! ( 1 , batches. len( ) ) ;
132
138
assert_eq ! ( 11 , batches[ 0 ] . num_columns( ) ) ;
@@ -138,9 +144,10 @@ mod tests {
138
144
#[ tokio:: test]
139
145
async fn read_alltypes_plain_avro ( ) -> Result < ( ) > {
140
146
let session_ctx = SessionContext :: new ( ) ;
141
- let task_ctx = session_ctx. task_ctx ( ) ;
147
+ let ctx = session_ctx. state ( ) ;
148
+ let task_ctx = ctx. task_ctx ( ) ;
142
149
let projection = None ;
143
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
150
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
144
151
145
152
let x: Vec < String > = exec
146
153
. schema ( )
@@ -190,9 +197,10 @@ mod tests {
190
197
#[ tokio:: test]
191
198
async fn read_bool_alltypes_plain_avro ( ) -> Result < ( ) > {
192
199
let session_ctx = SessionContext :: new ( ) ;
193
- let task_ctx = session_ctx. task_ctx ( ) ;
200
+ let ctx = session_ctx. state ( ) ;
201
+ let task_ctx = ctx. task_ctx ( ) ;
194
202
let projection = Some ( vec ! [ 1 ] ) ;
195
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
203
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
196
204
197
205
let batches = collect ( exec, task_ctx) . await ?;
198
206
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -216,9 +224,10 @@ mod tests {
216
224
#[ tokio:: test]
217
225
async fn read_i32_alltypes_plain_avro ( ) -> Result < ( ) > {
218
226
let session_ctx = SessionContext :: new ( ) ;
219
- let task_ctx = session_ctx. task_ctx ( ) ;
227
+ let ctx = session_ctx. state ( ) ;
228
+ let task_ctx = ctx. task_ctx ( ) ;
220
229
let projection = Some ( vec ! [ 0 ] ) ;
221
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
230
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
222
231
223
232
let batches = collect ( exec, task_ctx) . await ?;
224
233
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -239,9 +248,10 @@ mod tests {
239
248
#[ tokio:: test]
240
249
async fn read_i96_alltypes_plain_avro ( ) -> Result < ( ) > {
241
250
let session_ctx = SessionContext :: new ( ) ;
242
- let task_ctx = session_ctx. task_ctx ( ) ;
251
+ let ctx = session_ctx. state ( ) ;
252
+ let task_ctx = ctx. task_ctx ( ) ;
243
253
let projection = Some ( vec ! [ 10 ] ) ;
244
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
254
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
245
255
246
256
let batches = collect ( exec, task_ctx) . await ?;
247
257
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -262,9 +272,10 @@ mod tests {
262
272
#[ tokio:: test]
263
273
async fn read_f32_alltypes_plain_avro ( ) -> Result < ( ) > {
264
274
let session_ctx = SessionContext :: new ( ) ;
265
- let task_ctx = session_ctx. task_ctx ( ) ;
275
+ let ctx = session_ctx. state ( ) ;
276
+ let task_ctx = ctx. task_ctx ( ) ;
266
277
let projection = Some ( vec ! [ 6 ] ) ;
267
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
278
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
268
279
269
280
let batches = collect ( exec, task_ctx) . await ?;
270
281
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -288,9 +299,10 @@ mod tests {
288
299
#[ tokio:: test]
289
300
async fn read_f64_alltypes_plain_avro ( ) -> Result < ( ) > {
290
301
let session_ctx = SessionContext :: new ( ) ;
291
- let task_ctx = session_ctx. task_ctx ( ) ;
302
+ let ctx = session_ctx. state ( ) ;
303
+ let task_ctx = ctx. task_ctx ( ) ;
292
304
let projection = Some ( vec ! [ 7 ] ) ;
293
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
305
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
294
306
295
307
let batches = collect ( exec, task_ctx) . await ?;
296
308
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -314,9 +326,10 @@ mod tests {
314
326
#[ tokio:: test]
315
327
async fn read_binary_alltypes_plain_avro ( ) -> Result < ( ) > {
316
328
let session_ctx = SessionContext :: new ( ) ;
317
- let task_ctx = session_ctx. task_ctx ( ) ;
329
+ let ctx = session_ctx. state ( ) ;
330
+ let task_ctx = ctx. task_ctx ( ) ;
318
331
let projection = Some ( vec ! [ 9 ] ) ;
319
- let exec = get_exec ( "alltypes_plain.avro" , projection, None ) . await ?;
332
+ let exec = get_exec ( & ctx , "alltypes_plain.avro" , projection, None ) . await ?;
320
333
321
334
let batches = collect ( exec, task_ctx) . await ?;
322
335
assert_eq ! ( batches. len( ) , 1 ) ;
@@ -338,14 +351,15 @@ mod tests {
338
351
}
339
352
340
353
async fn get_exec (
354
+ ctx : & SessionState ,
341
355
file_name : & str ,
342
356
projection : Option < Vec < usize > > ,
343
357
limit : Option < usize > ,
344
358
) -> Result < Arc < dyn ExecutionPlan > > {
345
359
let testdata = crate :: test_util:: arrow_test_data ( ) ;
346
360
let store_root = format ! ( "{}/avro" , testdata) ;
347
361
let format = AvroFormat { } ;
348
- scan_format ( & format, & store_root, file_name, projection, limit) . await
362
+ scan_format ( ctx , & format, & store_root, file_name, projection, limit) . await
349
363
}
350
364
}
351
365
@@ -356,13 +370,16 @@ mod tests {
356
370
357
371
use super :: super :: test_util:: scan_format;
358
372
use crate :: error:: DataFusionError ;
373
+ use crate :: prelude:: SessionContext ;
359
374
360
375
#[ tokio:: test]
361
376
async fn test ( ) -> Result < ( ) > {
377
+ let session_ctx = SessionContext :: new ( ) ;
378
+ let ctx = session_ctx. state ( ) ;
362
379
let format = AvroFormat { } ;
363
380
let testdata = crate :: test_util:: arrow_test_data ( ) ;
364
381
let filename = "avro/alltypes_plain.avro" ;
365
- let result = scan_format ( & format, & testdata, filename, None , None ) . await ;
382
+ let result = scan_format ( & ctx , & format, & testdata, filename, None , None ) . await ;
366
383
assert ! ( matches!(
367
384
result,
368
385
Err ( DataFusionError :: NotImplemented ( msg) )
0 commit comments