@@ -101,20 +101,11 @@ pub trait AsyncFileReader: Send {
101
101
/// Provides asynchronous access to the [`ParquetMetaData`] of a parquet file,
102
102
/// allowing fine-grained control over how metadata is sourced, in particular allowing
103
103
/// for caching, pre-fetching, catalog metadata, etc...
104
- fn get_metadata ( & mut self ) -> BoxFuture < ' _ , Result < Arc < ParquetMetaData > > > ;
105
-
106
- /// Provides asynchronous access to the [`ParquetMetaData`] of a parquet file,
107
- /// allowing fine-grained control over how metadata is sourced, in particular allowing
108
- /// for caching, pre-fetching, catalog metadata, decrypting, etc...
109
- ///
110
- /// By default calls `get_metadata()`
111
- fn get_metadata_with_options < ' a > (
104
+ /// ArrowReaderOptions may be provided to supply decryption parameters
105
+ fn get_metadata < ' a > (
112
106
& ' a mut self ,
113
- options : & ' a ArrowReaderOptions ,
114
- ) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
115
- let _ = options;
116
- self . get_metadata ( )
117
- }
107
+ options : Option < & ' a ArrowReaderOptions > ,
108
+ ) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > ;
118
109
}
119
110
120
111
/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader,
@@ -127,15 +118,11 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> {
127
118
self . as_mut ( ) . get_byte_ranges ( ranges)
128
119
}
129
120
130
- fn get_metadata ( & mut self ) -> BoxFuture < ' _ , Result < Arc < ParquetMetaData > > > {
131
- self . as_mut ( ) . get_metadata ( )
132
- }
133
-
134
- fn get_metadata_with_options < ' a > (
121
+ fn get_metadata < ' a > (
135
122
& ' a mut self ,
136
- options : & ' a ArrowReaderOptions ,
123
+ options : Option < & ' a ArrowReaderOptions > ,
137
124
) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
138
- self . as_mut ( ) . get_metadata_with_options ( options)
125
+ self . as_mut ( ) . get_metadata ( options)
139
126
}
140
127
}
141
128
@@ -156,9 +143,9 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
156
143
. boxed ( )
157
144
}
158
145
159
- fn get_metadata_with_options < ' a > (
146
+ fn get_metadata < ' a > (
160
147
& ' a mut self ,
161
- options : & ' a ArrowReaderOptions ,
148
+ options : Option < & ' a ArrowReaderOptions > ,
162
149
) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
163
150
const FOOTER_SIZE_I64 : i64 = FOOTER_SIZE as i64 ;
164
151
async move {
@@ -169,6 +156,7 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
169
156
170
157
let footer = ParquetMetaDataReader :: decode_footer_tail ( & buf) ?;
171
158
let metadata_len = footer. metadata_length ( ) ;
159
+
172
160
self . seek ( SeekFrom :: End ( -FOOTER_SIZE_I64 - metadata_len as i64 ) )
173
161
. await ?;
174
162
@@ -178,43 +166,16 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
178
166
let metadata_reader = ParquetMetaDataReader :: new ( ) ;
179
167
180
168
#[ cfg( feature = "encryption" ) ]
181
- let metadata_reader = metadata_reader
182
- . with_decryption_properties ( options. file_decryption_properties . as_ref ( ) ) ;
169
+ let metadata_reader = metadata_reader. with_decryption_properties (
170
+ options. and_then ( |o| o. file_decryption_properties . as_ref ( ) ) ,
171
+ ) ;
183
172
184
173
let parquet_metadata = metadata_reader. decode_footer_metadata ( & buf, & footer) ?;
185
174
186
175
Ok ( Arc :: new ( parquet_metadata) )
187
176
}
188
177
. boxed ( )
189
178
}
190
-
191
- fn get_metadata ( & mut self ) -> BoxFuture < ' _ , Result < Arc < ParquetMetaData > > > {
192
- const FOOTER_SIZE_I64 : i64 = FOOTER_SIZE as i64 ;
193
- async move {
194
- self . seek ( SeekFrom :: End ( -FOOTER_SIZE_I64 ) ) . await ?;
195
-
196
- let mut buf = [ 0_u8 ; FOOTER_SIZE ] ;
197
- self . read_exact ( & mut buf) . await ?;
198
-
199
- let footer = ParquetMetaDataReader :: decode_footer_tail ( & buf) ?;
200
- let metadata_len = footer. metadata_length ( ) ;
201
-
202
- if footer. is_encrypted_footer ( ) {
203
- return Err ( general_err ! (
204
- "Parquet file has an encrypted footer but decryption properties were not provided"
205
- ) ) ;
206
- }
207
-
208
- self . seek ( SeekFrom :: End ( -FOOTER_SIZE_I64 - metadata_len as i64 ) )
209
- . await ?;
210
-
211
- let mut buf = Vec :: with_capacity ( metadata_len) ;
212
- self . take ( metadata_len as _ ) . read_to_end ( & mut buf) . await ?;
213
-
214
- Ok ( Arc :: new ( ParquetMetaDataReader :: decode_metadata ( & buf) ?) )
215
- }
216
- . boxed ( )
217
- }
218
179
}
219
180
220
181
impl ArrowReaderMetadata {
@@ -233,7 +194,7 @@ impl ArrowReaderMetadata {
233
194
) -> Result < Self > {
234
195
// TODO: this is all rather awkward. It would be nice if AsyncFileReader::get_metadata
235
196
// took an argument to fetch the page indexes.
236
- let mut metadata = input. get_metadata_with_options ( & options) . await ?;
197
+ let mut metadata = input. get_metadata ( Some ( & options) ) . await ?;
237
198
238
199
if options. page_index
239
200
&& metadata. column_index ( ) . is_none ( )
@@ -1169,13 +1130,9 @@ mod tests {
1169
1130
futures:: future:: ready ( Ok ( self . data . slice ( range) ) ) . boxed ( )
1170
1131
}
1171
1132
1172
- fn get_metadata ( & mut self ) -> BoxFuture < ' _ , Result < Arc < ParquetMetaData > > > {
1173
- futures:: future:: ready ( Ok ( self . metadata . clone ( ) ) ) . boxed ( )
1174
- }
1175
-
1176
- fn get_metadata_with_options < ' a > (
1133
+ fn get_metadata < ' a > (
1177
1134
& ' a mut self ,
1178
- _options : & ' a ArrowReaderOptions ,
1135
+ _options : Option < & ' a ArrowReaderOptions > ,
1179
1136
) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
1180
1137
futures:: future:: ready ( Ok ( self . metadata . clone ( ) ) ) . boxed ( )
1181
1138
}
0 commit comments