feat: register functions from Python

This commit is contained in:
Xuanwo
2026-08-12 05:34:28 +08:00
parent 65c0968c0f
commit 206efd98ff
7 changed files with 526 additions and 3 deletions
+20
View File
@@ -23,6 +23,7 @@ use lancedb::{
connection::NamespaceClientPushdownOperation,
database::namespace::LanceNamespaceDatabase,
database::{CreateTableMode, Database, ReadConsistency},
function::RegisterFunctionJobSpec,
};
use pyo3::{
Bound, FromPyObject, Py, PyAny, PyRef, PyResult, Python,
@@ -589,6 +590,25 @@ impl Connection {
})
})
}
/// Submit a first-class Function registration job.
///
/// Accepts the exact private [`crate::function::PyFunctionDefinition`] and
/// builds [`RegisterFunctionJobSpec`] with `expected_current_function_id =
/// None` (create-if-absent). Does not JSON round-trip the definition.
pub fn _register_function<'py>(
self_: PyRef<'py, Self>,
name: String,
definition: Bound<'_, crate::function::PyFunctionDefinition>,
) -> PyResult<Bound<'py, PyAny>> {
let inner = self_.get_inner()?.clone();
let definition = definition.get().inner().clone();
future_into_py(self_.py(), async move {
let spec = RegisterFunctionJobSpec::try_new(name, definition, None).infer_error()?;
let job = inner.register_function(spec).await.infer_error()?;
Ok(crate::job::Job::new(job))
})
}
}
#[pyfunction]
+1 -2
View File
@@ -93,8 +93,7 @@ impl PyFunctionDefinition {
Self { inner }
}
/// Crate-private accessor for later registration slices.
#[allow(dead_code)]
/// Crate-private accessor for registration submit bindings.
pub(crate) fn inner(&self) -> &FunctionDefinition {
&self.inner
}