66
77use std:: any:: Any ;
88use std:: fmt:: { self , Debug } ;
9- use std:: path:: PathBuf ;
109use std:: sync:: Arc ;
1110
1211use arrow:: array:: { ArrayRef , RecordBatch , UInt64Array } ;
1312use arrow:: datatypes:: { DataType , Field , Schema , SchemaRef } ;
1413use datafusion:: error:: { DataFusionError , Result as DataFusionResult } ;
14+ use datafusion:: execution:: object_store:: ObjectStoreUrl ;
1515use datafusion:: execution:: { SendableRecordBatchStream , TaskContext } ;
1616use datafusion:: physical_expr:: { EquivalenceProperties , Partitioning } ;
1717use datafusion:: physical_plan:: stream:: RecordBatchStreamAdapter ;
@@ -38,7 +38,7 @@ pub struct DuckLakeInsertExec {
3838 table_name : String ,
3939 arrow_schema : SchemaRef ,
4040 write_mode : WriteMode ,
41- data_path : PathBuf ,
41+ object_store_url : Arc < ObjectStoreUrl > ,
4242 cache : PlanProperties ,
4343}
4444
@@ -51,7 +51,7 @@ impl DuckLakeInsertExec {
5151 table_name : String ,
5252 arrow_schema : SchemaRef ,
5353 write_mode : WriteMode ,
54- data_path : PathBuf ,
54+ object_store_url : Arc < ObjectStoreUrl > ,
5555 ) -> Self {
5656 let cache = Self :: compute_properties ( ) ;
5757 Self {
@@ -61,7 +61,7 @@ impl DuckLakeInsertExec {
6161 table_name,
6262 arrow_schema,
6363 write_mode,
64- data_path ,
64+ object_store_url ,
6565 cache,
6666 }
6767 }
@@ -82,7 +82,6 @@ impl Debug for DuckLakeInsertExec {
8282 . field ( "schema_name" , & self . schema_name )
8383 . field ( "table_name" , & self . table_name )
8484 . field ( "write_mode" , & self . write_mode )
85- . field ( "data_path" , & self . data_path )
8685 . finish_non_exhaustive ( )
8786 }
8887}
@@ -136,7 +135,7 @@ impl ExecutionPlan for DuckLakeInsertExec {
136135 self . table_name . clone ( ) ,
137136 Arc :: clone ( & self . arrow_schema ) ,
138137 self . write_mode ,
139- self . data_path . clone ( ) ,
138+ self . object_store_url . clone ( ) ,
140139 ) ) )
141140 }
142141
@@ -158,19 +157,24 @@ impl ExecutionPlan for DuckLakeInsertExec {
158157 let table_name = self . table_name . clone ( ) ;
159158 let arrow_schema = Arc :: clone ( & self . arrow_schema ) ;
160159 let write_mode = self . write_mode ;
161- let data_path = self . data_path . clone ( ) ;
160+ let object_store_url = self . object_store_url . clone ( ) ;
162161 let output_schema = make_insert_count_schema ( ) ;
163162
164163 let stream = stream:: once ( async move {
165- let input_stream = input. execute ( 0 , context) ?;
164+ let input_stream = input. execute ( 0 , Arc :: clone ( & context) ) ?;
166165 let batches: Vec < RecordBatch > = input_stream. try_collect ( ) . await ?;
167166
168167 if batches. is_empty ( ) {
169168 let count_array: ArrayRef = Arc :: new ( UInt64Array :: from ( vec ! [ 0u64 ] ) ) ;
170169 return Ok ( RecordBatch :: try_new ( output_schema, vec ! [ count_array] ) ?) ;
171170 }
172171
173- let table_writer = DuckLakeTableWriter :: new ( writer)
172+ // Get object store from runtime environment
173+ let object_store = context
174+ . runtime_env ( )
175+ . object_store ( object_store_url. as_ref ( ) ) ?;
176+
177+ let table_writer = DuckLakeTableWriter :: new ( writer, object_store)
174178 . map_err ( |e| DataFusionError :: External ( Box :: new ( e) ) ) ?;
175179
176180 let schema_without_metadata =
@@ -185,8 +189,6 @@ impl ExecutionPlan for DuckLakeInsertExec {
185189 )
186190 . map_err ( |e| DataFusionError :: External ( Box :: new ( e) ) ) ?;
187191
188- let _ = data_path;
189-
190192 for batch in & batches {
191193 session
192194 . write_batch ( batch)
@@ -197,6 +199,7 @@ impl ExecutionPlan for DuckLakeInsertExec {
197199
198200 session
199201 . finish ( )
202+ . await
200203 . map_err ( |e| DataFusionError :: External ( Box :: new ( e) ) ) ?;
201204
202205 let count_array: ArrayRef = Arc :: new ( UInt64Array :: from ( vec ! [ row_count] ) ) ;
0 commit comments