@@ -120,8 +120,8 @@ pub unsafe extern "C" fn connectorx_rewrite(
120120
121121#[ repr( C ) ]
122122pub struct CXArray {
123- array : * const FFI_ArrowArray ,
124- schema : * const FFI_ArrowSchema ,
123+ array : FFI_ArrowArray ,
124+ schema : FFI_ArrowSchema ,
125125}
126126
127127#[ repr( C ) ]
@@ -142,17 +142,6 @@ pub unsafe fn free_str(ptr: *const c_char) {
142142pub unsafe extern "C" fn free_result ( res : * const CXResult ) {
143143 let header = get_vec :: < _ > ( ( * res) . header . ptr , ( * res) . header . len , ( * res) . header . capacity ) ;
144144 header. into_iter ( ) . for_each ( |col| free_str ( col) ) ;
145-
146- let rbs = get_vec :: < _ > ( ( * res) . data . ptr , ( * res) . data . len , ( * res) . data . capacity ) ;
147- rbs. into_iter ( ) . for_each ( |rb| {
148- get_vec :: < _ > ( rb. ptr , rb. len , rb. capacity )
149- . into_iter ( )
150- . for_each ( |a| {
151- // Otherwise memory leak
152- std:: sync:: Arc :: from_raw ( a. array ) ;
153- std:: sync:: Arc :: from_raw ( a. schema ) ;
154- } )
155- } ) ;
156145}
157146
158147#[ no_mangle]
@@ -183,13 +172,10 @@ pub unsafe extern "C" fn connectorx_scan(conn: *const c_char, query: *const c_ch
183172 let mut cols = vec ! [ ] ;
184173
185174 for array in rb. columns ( ) {
186- let data = array. data ( ) . clone ( ) ;
187- let array = ArrowArray :: try_new ( data) . expect ( "c ptr" ) ;
188- let ( array_ptr, schema_ptr) = ArrowArray :: into_raw ( array) ;
189-
175+ let data = array. to_data ( ) ;
190176 let cx_array = CXArray {
191- array : array_ptr ,
192- schema : schema_ptr ,
177+ schema : FFI_ArrowSchema :: try_from ( data . data_type ( ) ) . unwrap ( ) ,
178+ array : FFI_ArrowArray :: new ( & data ) ,
193179 } ;
194180 cols. push ( cx_array) ;
195181 }
@@ -217,32 +203,6 @@ pub unsafe extern "C" fn free_iter(iter: *mut Box<dyn RecordBatchIterator>) {
217203 let _ = Box :: from_raw ( iter) ;
218204}
219205
220- #[ no_mangle]
221- pub unsafe extern "C" fn free_schema ( schema : * mut CXSchema ) {
222- let res = Box :: from_raw ( schema) ;
223-
224- let header = get_vec :: < _ > ( res. headers . ptr , res. headers . len , res. headers . capacity ) ;
225- header. into_iter ( ) . for_each ( |col| free_str ( col) ) ;
226-
227- get_vec :: < _ > ( res. types . ptr , res. types . len , res. types . capacity )
228- . into_iter ( )
229- . for_each ( |a| {
230- std:: sync:: Arc :: from_raw ( a. array ) ;
231- std:: sync:: Arc :: from_raw ( a. schema ) ;
232- } ) ;
233- }
234-
235- #[ no_mangle]
236- pub unsafe extern "C" fn free_record_batch ( rb : * mut CXSlice < CXArray > ) {
237- let slice = Box :: from_raw ( rb) ;
238- get_vec :: < _ > ( slice. ptr , slice. len , slice. capacity )
239- . into_iter ( )
240- . for_each ( |a| {
241- std:: sync:: Arc :: from_raw ( a. array ) ;
242- std:: sync:: Arc :: from_raw ( a. schema ) ;
243- } )
244- }
245-
246206#[ no_mangle]
247207pub unsafe extern "C" fn connectorx_scan_iter (
248208 conn : * const c_char ,
@@ -274,12 +234,10 @@ pub unsafe extern "C" fn connectorx_get_schema(
274234 let ( empty_batch, names) = arrow_iter. get_schema ( ) ;
275235 let mut cols = vec ! [ ] ;
276236 for array in empty_batch. columns ( ) {
277- let data = array. data ( ) . clone ( ) ;
278- let array = ArrowArray :: try_new ( data) . expect ( "c ptr" ) ;
279- let ( array_ptr, schema_ptr) = ArrowArray :: into_raw ( array) ;
237+ let data = array. to_data ( ) ;
280238 let cx_array = CXArray {
281- array : array_ptr ,
282- schema : schema_ptr ,
239+ schema : FFI_ArrowSchema :: try_from ( data . data_type ( ) ) . unwrap ( ) ,
240+ array : FFI_ArrowArray :: new ( & data ) ,
283241 } ;
284242 cols. push ( cx_array) ;
285243 }
@@ -317,13 +275,10 @@ pub unsafe extern "C" fn connectorx_iter_next(
317275 let mut cols = vec ! [ ] ;
318276
319277 for array in rb. columns ( ) {
320- let data = array. data ( ) . clone ( ) ;
321- let array = ArrowArray :: try_new ( data) . expect ( "c ptr" ) ;
322- let ( array_ptr, schema_ptr) = ArrowArray :: into_raw ( array) ;
323-
278+ let data = array. to_data ( ) ;
324279 let cx_array = CXArray {
325- array : array_ptr ,
326- schema : schema_ptr ,
280+ schema : FFI_ArrowSchema :: try_from ( data . data_type ( ) ) . unwrap ( ) ,
281+ array : FFI_ArrowArray :: new ( & data ) ,
327282 } ;
328283 cols. push ( cx_array) ;
329284 }
0 commit comments