@@ -34,6 +34,7 @@ use crate::read::row_based::batch::BytesBatch;
34
34
struct FileState {
35
35
file : OneFilePartition ,
36
36
offset : usize ,
37
+ reader : opendal:: Reader ,
37
38
}
38
39
pub struct BytesReader {
39
40
table_ctx : Arc < dyn TableContext > ,
@@ -62,14 +63,8 @@ impl BytesReader {
62
63
pub async fn read_batch ( & mut self ) -> Result < DataBlock > {
63
64
if let Some ( state) = & mut self . file_state {
64
65
let end = min ( self . read_batch_size + state. offset , state. file . size ) ;
65
- let mut reader = self
66
- . op
67
- . reader_with ( & state. file . path )
68
- . range ( ( state. offset as u64 ) ..( end as u64 ) )
69
- . await ?;
70
-
71
66
let mut buffer = vec ! [ 0u8 ; end - state. offset] ;
72
- let n = read_full ( & mut reader, & mut buffer[ 0 ..] ) . await ?;
67
+ let n = read_full ( & mut state . reader , & mut buffer[ ..] ) . await ?;
73
68
if n == 0 {
74
69
return Err ( ErrorCode :: BadBytes ( format ! (
75
70
"Unexpected EOF {} expect {} bytes, read only {} bytes." ,
@@ -123,7 +118,13 @@ impl PrefetchAsyncSource for BytesReader {
123
118
None => return Ok ( None ) ,
124
119
} ;
125
120
let file = OneFilePartition :: from_part ( & part) ?. clone ( ) ;
126
- self . file_state = Some ( FileState { file, offset : 0 } )
121
+
122
+ let reader = self . op . reader_with ( & file. path ) . await ?;
123
+ self . file_state = Some ( FileState {
124
+ file,
125
+ reader,
126
+ offset : 0 ,
127
+ } )
127
128
}
128
129
match self . read_batch ( ) . await {
129
130
Ok ( block) => Ok ( Some ( block) ) ,
0 commit comments