@@ -101,20 +101,11 @@ pub trait AsyncFileReader: Send {
101101 /// Provides asynchronous access to the [`ParquetMetaData`] of a parquet file,
102102 /// allowing fine-grained control over how metadata is sourced, in particular allowing
103103 /// 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 > (
112106 & ' 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 > > > ;
118109}
119110
120111/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader,
@@ -127,15 +118,11 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> {
127118 self . as_mut ( ) . get_byte_ranges ( ranges)
128119 }
129120
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 > (
135122 & ' a mut self ,
136- options : & ' a ArrowReaderOptions ,
123+ options : Option < & ' a ArrowReaderOptions > ,
137124 ) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
138- self . as_mut ( ) . get_metadata_with_options ( options)
125+ self . as_mut ( ) . get_metadata ( options)
139126 }
140127}
141128
@@ -156,9 +143,9 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
156143 . boxed ( )
157144 }
158145
159- fn get_metadata_with_options < ' a > (
146+ fn get_metadata < ' a > (
160147 & ' a mut self ,
161- options : & ' a ArrowReaderOptions ,
148+ options : Option < & ' a ArrowReaderOptions > ,
162149 ) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
163150 const FOOTER_SIZE_I64 : i64 = FOOTER_SIZE as i64 ;
164151 async move {
@@ -169,6 +156,7 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
169156
170157 let footer = ParquetMetaDataReader :: decode_footer_tail ( & buf) ?;
171158 let metadata_len = footer. metadata_length ( ) ;
159+
172160 self . seek ( SeekFrom :: End ( -FOOTER_SIZE_I64 - metadata_len as i64 ) )
173161 . await ?;
174162
@@ -178,43 +166,16 @@ impl<T: AsyncRead + AsyncSeek + Unpin + Send> AsyncFileReader for T {
178166 let metadata_reader = ParquetMetaDataReader :: new ( ) ;
179167
180168 #[ 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+ ) ;
183172
184173 let parquet_metadata = metadata_reader. decode_footer_metadata ( & buf, & footer) ?;
185174
186175 Ok ( Arc :: new ( parquet_metadata) )
187176 }
188177 . boxed ( )
189178 }
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- }
218179}
219180
220181impl ArrowReaderMetadata {
@@ -233,7 +194,7 @@ impl ArrowReaderMetadata {
233194 ) -> Result < Self > {
234195 // TODO: this is all rather awkward. It would be nice if AsyncFileReader::get_metadata
235196 // 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 ?;
237198
238199 if options. page_index
239200 && metadata. column_index ( ) . is_none ( )
@@ -1169,13 +1130,9 @@ mod tests {
11691130 futures:: future:: ready ( Ok ( self . data . slice ( range) ) ) . boxed ( )
11701131 }
11711132
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 > (
11771134 & ' a mut self ,
1178- _options : & ' a ArrowReaderOptions ,
1135+ _options : Option < & ' a ArrowReaderOptions > ,
11791136 ) -> BoxFuture < ' a , Result < Arc < ParquetMetaData > > > {
11801137 futures:: future:: ready ( Ok ( self . metadata . clone ( ) ) ) . boxed ( )
11811138 }
0 commit comments