Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Catalog trait as python binding #604

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ crate-type = ["cdylib"]
iceberg = { path = "../../crates/iceberg" }
pyo3 = { version = "0.21.1", features = ["extension-module"] }
arrow = { version = "52.2.0", features = ["pyarrow"] }
iceberg-catalog-sql = { path = "../../crates/catalog/sql" }
55 changes: 55 additions & 0 deletions bindings/python/src/catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;


use std::collections::HashMap;

use iceberg_catalog_sql::{SqlCatalog, SqlCatalogConfig, SqlBindStyle};
use iceberg::catalog::NamespaceIdent;
use iceberg::io::FileIO;



#[pyclass]
pub struct PySqlCatalog {
inner: SqlCatalog,
}

#[pymethods]
impl PySqlCatalog {
#[new]
fn new(uri: String, name: String, warehouse_location: String, sql_bind_style: String) -> PyResult<Self> {
let sql_bind_style = match sql_bind_style.as_str() {
"DollarNumeric" => SqlBindStyle::DollarNumeric,
"QMark" => SqlBindStyle::QMark,
_ => return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>("Invalid SqlBindStyle")),
};

let config = SqlCatalogConfig {
uri,
name,
warehouse_location,
file_io: FileIO::from_path(&warehouse_location).unwrap().build().unwrap(),
sql_bind_style,
props: HashMap::new(),
};

let inner = SqlCatalog::new(config).unwrap();

Ok(PySqlCatalog { inner })
}

fn list_namespaces(&self, parent: Option<String>) -> PyResult<Vec<String>> {
let parent_ident = parent.map(|p| NamespaceIdent::new(p));
let namespaces = self.inner.list_namespaces(parent_ident.as_ref()).unwrap();
Ok(namespaces.into_iter().map(|ns| ns.to_string()).collect())
}

fn create_namespace(&self, namespace: String, properties: HashMap<String, String>) -> PyResult<()> {
let namespace_ident = NamespaceIdent::new(namespace);
self.inner.create_namespace(&namespace_ident, properties).unwrap();
Ok(())
}

// Add other methods similarly...
}
2 changes: 2 additions & 0 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

mod transform;
mod catalog;

#[pyfunction]
fn hello_world() -> PyResult<String> {
Expand All @@ -33,5 +34,6 @@ fn pyiceberg_core_rust(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(hello_world, m)?)?;

m.add_class::<transform::ArrowArrayTransform>()?;
m.add_class::<catalog::PySqlCatalog>()?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/iceberg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern crate derive_builder;
mod error;
pub use error::{Error, ErrorKind, Result};

mod catalog;
pub mod catalog;

pub use catalog::{
Catalog, Namespace, NamespaceIdent, TableCommit, TableCreation, TableIdent, TableRequirement,
Expand Down
Loading