@@ -78,7 +78,7 @@ use crate::delta_datafusion::expr::parse_predicate_expression;
78
78
use crate :: delta_datafusion:: schema_adapter:: DeltaSchemaAdapterFactory ;
79
79
use crate :: errors:: { DeltaResult , DeltaTableError } ;
80
80
use crate :: kernel:: { Add , DataCheck , EagerSnapshot , Invariant , Snapshot , StructTypeExt } ;
81
- use crate :: logstore:: LogStoreRef ;
81
+ use crate :: logstore:: { logstore_for , object_store_url , LogStoreRef } ;
82
82
use crate :: table:: builder:: ensure_table_uri;
83
83
use crate :: table:: state:: DeltaTableState ;
84
84
use crate :: table:: Constraint ;
@@ -342,6 +342,7 @@ pub struct DeltaScanConfigBuilder {
342
342
enable_parquet_pushdown : bool ,
343
343
/// Schema to scan table with
344
344
schema : Option < SchemaRef > ,
345
+ options : HashMap < String , String > ,
345
346
}
346
347
347
348
impl Default for DeltaScanConfigBuilder {
@@ -352,6 +353,7 @@ impl Default for DeltaScanConfigBuilder {
352
353
wrap_partition_values : None ,
353
354
enable_parquet_pushdown : true ,
354
355
schema : None ,
356
+ options : HashMap :: new ( ) ,
355
357
}
356
358
}
357
359
}
@@ -396,6 +398,11 @@ impl DeltaScanConfigBuilder {
396
398
self
397
399
}
398
400
401
+ pub fn with_options ( mut self , options : HashMap < String , String > ) -> Self {
402
+ self . options = options;
403
+ self
404
+ }
405
+
399
406
/// Build a DeltaScanConfig and ensure no column name conflicts occur during downstream processing
400
407
pub fn build ( & self , snapshot : & DeltaTableState ) -> DeltaResult < DeltaScanConfig > {
401
408
let file_column_name = if self . include_file_column {
@@ -438,6 +445,7 @@ impl DeltaScanConfigBuilder {
438
445
wrap_partition_values : self . wrap_partition_values . unwrap_or ( true ) ,
439
446
enable_parquet_pushdown : self . enable_parquet_pushdown ,
440
447
schema : self . schema . clone ( ) ,
448
+ options : self . options . clone ( ) ,
441
449
} )
442
450
}
443
451
}
@@ -453,6 +461,8 @@ pub struct DeltaScanConfig {
453
461
pub enable_parquet_pushdown : bool ,
454
462
/// Schema to read as
455
463
pub schema : Option < SchemaRef > ,
464
+
465
+ pub options : HashMap < String , String > ,
456
466
}
457
467
458
468
pub ( crate ) struct DeltaScanBuilder < ' a > {
@@ -730,11 +740,14 @@ impl TableProvider for DeltaTable {
730
740
) -> DataFusionResult < Arc < dyn ExecutionPlan > > {
731
741
register_store ( self . log_store ( ) , session. runtime_env ( ) . clone ( ) ) ;
732
742
let filter_expr = conjunction ( filters. iter ( ) . cloned ( ) ) ;
743
+ let mut config = DeltaScanConfig :: default ( ) ;
744
+ config. options = self . config . options . clone ( ) ;
733
745
734
746
let scan = DeltaScanBuilder :: new ( self . snapshot ( ) ?, self . log_store ( ) , session)
735
747
. with_projection ( projection)
736
748
. with_limit ( limit)
737
749
. with_filter ( filter_expr)
750
+ . with_scan_config ( config)
738
751
. build ( )
739
752
. await ?;
740
753
@@ -753,12 +766,15 @@ impl TableProvider for DeltaTable {
753
766
754
767
register_store ( self . log_store ( ) , session_state. runtime_env ( ) . clone ( ) ) ;
755
768
let filter_expr = conjunction ( filters. iter ( ) . cloned ( ) ) ;
769
+ let mut config = DeltaScanConfig :: default ( ) ;
770
+ config. options = self . config . options . clone ( ) ;
756
771
757
772
let scan = DeltaScanBuilder :: new ( self . snapshot ( ) ?, self . log_store ( ) , session_state)
758
773
. with_projection ( projection)
759
774
. with_projection_deep ( projection_deep)
760
775
. with_limit ( limit)
761
776
. with_filter ( filter_expr)
777
+ . with_scan_config ( config)
762
778
. build ( )
763
779
. await ?;
764
780
@@ -970,6 +986,22 @@ impl ExecutionPlan for DeltaScan {
970
986
partition : usize ,
971
987
context : Arc < TaskContext > ,
972
988
) -> DataFusionResult < SendableRecordBatchStream > {
989
+ let source_uri = Url :: parse ( self . table_uri . as_str ( ) )
990
+ . map_err ( |e| DataFusionError :: External ( Box :: new ( e) ) ) ?;
991
+ let url_key = object_store_url ( & source_uri) ;
992
+ let runtime = context. runtime_env ( ) ;
993
+ if runtime. object_store ( url_key) . is_err ( ) {
994
+ let source_store = logstore_for ( source_uri, self . config . options . clone ( ) , None )
995
+ . map_err ( |e| DataFusionError :: External ( Box :: new ( e) ) ) ?;
996
+ let object_store_url = source_store. object_store_url ( ) ;
997
+
998
+ // check if delta store is already registered
999
+ if runtime. object_store ( object_store_url. clone ( ) ) . is_err ( ) {
1000
+ runtime
1001
+ . register_object_store ( object_store_url. as_ref ( ) , source_store. object_store ( ) ) ;
1002
+ }
1003
+ }
1004
+ // Now that everything is set up, execute the inner Delta
973
1005
self . parquet_scan . execute ( partition, context)
974
1006
}
975
1007
0 commit comments