@@ -61,7 +61,7 @@ use datafusion_physical_plan::{DisplayAs, DisplayFormatType, ExecutionPlan};
6161use datafusion_session:: Session ;
6262
6363use crate :: can_expr_be_pushed_down_with_schemas;
64- use crate :: source:: ParquetSource ;
64+ use crate :: source:: { parse_coerce_int96_string , ParquetSource } ;
6565use async_trait:: async_trait;
6666use bytes:: Bytes ;
6767use datafusion_datasource:: source:: DataSourceExec ;
@@ -304,9 +304,10 @@ async fn fetch_schema_with_location(
304304 store : & dyn ObjectStore ,
305305 file : & ObjectMeta ,
306306 metadata_size_hint : Option < usize > ,
307+ coerce_int96 : Option < TimeUnit > ,
307308) -> Result < ( Path , Schema ) > {
308309 let loc_path = file. location . clone ( ) ;
309- let schema = fetch_schema ( store, file, metadata_size_hint) . await ?;
310+ let schema = fetch_schema ( store, file, metadata_size_hint, coerce_int96 ) . await ?;
310311 Ok ( ( loc_path, schema) )
311312}
312313
@@ -337,12 +338,17 @@ impl FileFormat for ParquetFormat {
337338 store : & Arc < dyn ObjectStore > ,
338339 objects : & [ ObjectMeta ] ,
339340 ) -> Result < SchemaRef > {
341+ let coerce_int96 = match self . coerce_int96 ( ) {
342+ Some ( time_unit) => Some ( parse_coerce_int96_string ( time_unit. as_str ( ) ) ?) ,
343+ None => None ,
344+ } ;
340345 let mut schemas: Vec < _ > = futures:: stream:: iter ( objects)
341346 . map ( |object| {
342347 fetch_schema_with_location (
343348 store. as_ref ( ) ,
344349 object,
345350 self . metadata_size_hint ( ) ,
351+ coerce_int96,
346352 )
347353 } )
348354 . boxed ( ) // Workaround https://github.com/rust-lang/rust/issues/64552
@@ -825,13 +831,19 @@ async fn fetch_schema(
825831 store : & dyn ObjectStore ,
826832 file : & ObjectMeta ,
827833 metadata_size_hint : Option < usize > ,
834+ coerce_int96 : Option < TimeUnit > ,
828835) -> Result < Schema > {
829836 let metadata = fetch_parquet_metadata ( store, file, metadata_size_hint) . await ?;
830837 let file_metadata = metadata. file_metadata ( ) ;
831838 let schema = parquet_to_arrow_schema (
832839 file_metadata. schema_descr ( ) ,
833840 file_metadata. key_value_metadata ( ) ,
834841 ) ?;
842+ let schema = coerce_int96
843+ . and_then ( |time_unit| {
844+ coerce_int96_to_resolution ( file_metadata. schema_descr ( ) , & schema, & time_unit)
845+ } )
846+ . unwrap_or ( schema) ;
835847 Ok ( schema)
836848}
837849
0 commit comments