Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

pub(crate) mod constants;
mod table_provider;
mod udf;
mod utils;

Expand Down
50 changes: 50 additions & 0 deletions python/src/table_provider/flatgeobuf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use datafusion::catalog::TableProvider;
use datafusion::datasource::listing::{
ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl,
};
use datafusion::prelude::SessionContext;
use datafusion_ffi::table_provider::FFI_TableProvider;
use geodatafusion_flatgeobuf::FlatGeobufFormat;
use pyo3::prelude::*;
use pyo3::types::PyCapsule;
use pyo3::{Bound, PyResult, Python, pyclass, pymethods};
use pyo3_async_runtimes::tokio::get_runtime;
use std::sync::Arc;

#[pyfunction]
pub(crate) fn new_flatgeobuf(path: &str) -> PyFlatGeobufTableProvider {
let format = Arc::new(FlatGeobufFormat::default());

let options = ListingOptions::new(format).with_file_extension(".fgb");

let table_path = ListingTableUrl::parse(path).unwrap();

let state = SessionContext::new().state();
let runtime = get_runtime();
let inferred_schema =
runtime.block_on(async { options.infer_schema(&state, &table_path).await.unwrap() });

let config = ListingTableConfig::new(table_path)
.with_listing_options(options)
.with_schema(inferred_schema);

let table = ListingTable::try_new(config).unwrap();
PyFlatGeobufTableProvider(Arc::new(table))
}

#[pyclass(module = "geodatafusion", name = "FlatGeobufTableProvider", frozen)]
pub(crate) struct PyFlatGeobufTableProvider(Arc<dyn TableProvider + Send>);

#[pymethods]
impl PyFlatGeobufTableProvider {
pub fn __datafusion_table_provider__<'py>(
&self,
py: Python<'py>,
) -> PyResult<Bound<'py, PyCapsule>> {
let name = cr"datafusion_table_provider".into();

let provider = FFI_TableProvider::new(self.0.clone(), false, None);

PyCapsule::new(py, provider, Some(name))
}
}
1 change: 1 addition & 0 deletions python/src/table_provider/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod flatgeobuf;
Loading