forked from datafusion-contrib/datafusion-table-providers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
57 lines (46 loc) · 1.41 KB
/
lib.rs
File metadata and controls
57 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{ffi::CString, sync::Arc};
use datafusion::catalog::TableProvider;
use datafusion_ffi::table_provider::FFI_TableProvider;
use pyo3::{prelude::*, types::PyCapsule};
#[pyclass(module = "datafusion_table_providers._internal")]
struct RawTableProvider {
pub(crate) table: Arc<dyn TableProvider + Send>,
pub(crate) supports_pushdown_filters: bool,
}
#[pymethods]
impl RawTableProvider {
fn __datafusion_table_provider__<'py>(
&self,
py: Python<'py>,
) -> PyResult<Bound<'py, PyCapsule>> {
let name = CString::new("datafusion_table_provider").unwrap();
let provider = FFI_TableProvider::new(
Arc::clone(&self.table),
self.supports_pushdown_filters,
None,
);
PyCapsule::new(py, provider, Some(name.clone()))
}
}
pub mod duckdb;
pub mod flight;
pub mod mysql;
pub mod odbc;
pub mod postgres;
pub mod sqlite;
pub mod utils;
#[pymodule]
// module name need to match project name
fn _internal(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<RawTableProvider>()?;
let sqlite = PyModule::new(py, "sqlite")?;
sqlite::init_module(&sqlite)?;
m.add_submodule(&sqlite)?;
let duckdb = PyModule::new(py, "duckdb")?;
duckdb::init_module(&duckdb)?;
m.add_submodule(&duckdb)?;
let odbc = PyModule::new(py, "odbc")?;
odbc::init_module(&odbc)?;
m.add_submodule(&odbc)?;
Ok(())
}