11use std:: {
22 any:: Any ,
33 ffi:: { c_char, c_int, c_void, CStr , CString } ,
4- ptr:: { addr_of, addr_of_mut} ,
54 sync:: Arc ,
65} ;
76
@@ -14,73 +13,20 @@ use async_trait::async_trait;
1413use datafusion:: {
1514 catalog:: { Session , TableProvider } ,
1615 common:: DFSchema ,
16+ datasource:: TableType ,
17+ error:: DataFusionError ,
1718 execution:: { context:: SessionState , session_state:: SessionStateBuilder } ,
19+ logical_expr:: TableProviderFilterPushDown ,
1820 physical_plan:: ExecutionPlan ,
19- prelude:: { Expr , SessionConfig } ,
20- } ;
21- use datafusion:: {
22- common:: Result , datasource:: TableType , logical_expr:: TableProviderFilterPushDown ,
21+ prelude:: Expr ,
2322} ;
2423use tokio:: runtime:: Runtime ;
2524
26- #[ repr( C ) ]
27- #[ derive( Debug ) ]
28- #[ allow( non_camel_case_types) ]
29- pub enum FFI_Constraint {
30- /// Columns with the given indices form a composite primary key (they are
31- /// jointly unique and not nullable):
32- PrimaryKey ( Vec < usize > ) ,
33- /// Columns with the given indices form a composite unique key:
34- Unique ( Vec < usize > ) ,
35- }
36-
37- #[ repr( C ) ]
38- #[ derive( Debug ) ]
39- #[ allow( missing_docs) ]
40- #[ allow( non_camel_case_types) ]
41- pub struct FFI_ExecutionPlan {
42- pub private_data : * mut c_void ,
43- }
44-
45- unsafe impl Send for FFI_ExecutionPlan { }
46-
47- struct ExecutionPlanPrivateData {
48- plan : Arc < dyn ExecutionPlan + Send > ,
49- last_error : Option < CString > ,
50- }
51-
52- #[ repr( C ) ]
53- #[ derive( Debug ) ]
54- #[ allow( missing_docs) ]
55- #[ allow( non_camel_case_types) ]
56- pub struct FFI_SessionConfig {
57- pub version : i64 ,
58-
59- pub private_data : * mut c_void ,
60- }
61-
62- unsafe impl Send for FFI_SessionConfig { }
63-
64- struct SessionConfigPrivateData {
65- config : SessionConfig ,
66- last_error : Option < CString > ,
67- }
68-
69- struct ExportedSessionConfig {
70- session : * mut FFI_SessionConfig ,
71- }
72-
73- impl ExportedSessionConfig {
74- fn get_private_data ( & mut self ) -> & mut SessionConfigPrivateData {
75- unsafe { & mut * ( ( * self . session ) . private_data as * mut SessionConfigPrivateData ) }
76- }
77- }
78-
79- #[ repr( C ) ]
80- #[ derive( Debug ) ]
81- #[ allow( missing_docs) ]
82- #[ allow( non_camel_case_types) ]
83- pub struct FFI_Expr { }
25+ use super :: {
26+ execution_plan:: { ExecutionPlanPrivateData , FFI_ExecutionPlan } ,
27+ session_config:: { FFI_SessionConfig , SessionConfigPrivateData } ,
28+ } ;
29+ use datafusion:: error:: Result ;
8430
8531#[ repr( C ) ]
8632#[ derive( Debug ) ]
@@ -121,7 +67,6 @@ struct ConstExportedTableProvider {
12167
12268// The callback used to get array schema
12369unsafe extern "C" fn provider_schema ( provider : * const FFI_TableProvider ) -> FFI_ArrowSchema {
124- println ! ( "callback function" ) ;
12570 ConstExportedTableProvider { provider } . provider_schema ( )
12671}
12772
@@ -181,18 +126,12 @@ impl ConstExportedTableProvider {
181126 }
182127
183128 pub fn provider_schema ( & self ) -> FFI_ArrowSchema {
184- println ! ( "Enter exported table provider" ) ;
185129 let private_data = self . get_private_data ( ) ;
186130 let provider = & private_data. provider ;
187131
188- println ! ( "about to try from in provider.schema()" ) ;
189132 // This does silently fail because TableProvider does not return a result
190133 // so we expect it to always pass. Maybe some logging should be added.
191- let mut schema = FFI_ArrowSchema :: try_from ( provider. schema ( ) . as_ref ( ) )
192- . unwrap_or ( FFI_ArrowSchema :: empty ( ) ) ;
193-
194- println ! ( "Found the schema but can we return it?" ) ;
195- schema
134+ FFI_ArrowSchema :: try_from ( provider. schema ( ) . as_ref ( ) ) . unwrap_or ( FFI_ArrowSchema :: empty ( ) )
196135 }
197136}
198137
@@ -294,15 +233,7 @@ impl TableProvider for FFI_TableProvider {
294233 /// Get a reference to the schema for this table
295234 fn schema ( & self ) -> SchemaRef {
296235 let schema = match self . schema {
297- Some ( func) => {
298- println ! ( "About to call the function to get the schema" ) ;
299- unsafe {
300- let v = func ( self ) ;
301- println ! ( "Got the mutalbe ffi_arrow_schmea?" ) ;
302- // func(self).as_ref().and_then(|s| Schema::try_from(s).ok())
303- Schema :: try_from ( & func ( self ) ) . ok ( )
304- }
305- }
236+ Some ( func) => unsafe { Schema :: try_from ( & func ( self ) ) . ok ( ) } ,
306237 None => None ,
307238 } ;
308239 Arc :: new ( schema. unwrap_or ( Schema :: empty ( ) ) )
@@ -328,6 +259,10 @@ impl TableProvider for FFI_TableProvider {
328259 // The datasource should return *at least* this number of rows if available.
329260 _limit : Option < usize > ,
330261 ) -> Result < Arc < dyn ExecutionPlan > > {
262+ let scan_fn = self . scan . ok_or ( DataFusionError :: NotImplemented (
263+ "Scan not defined on FFI_TableProvider" . to_string ( ) ,
264+ ) ) ?;
265+
331266 Err ( datafusion:: error:: DataFusionError :: NotImplemented (
332267 "scan not implemented" . to_string ( ) ,
333268 ) )
0 commit comments