feat(python): expose remote function refresh jobs

This commit is contained in:
Xuanwo
2026-08-21 21:36:00 +08:00
parent a588208de6
commit 03ffb08ddd
9 changed files with 141 additions and 5 deletions
+56
View File
@@ -22,6 +22,12 @@ pub struct FunctionJob {
inner: Arc<lancedb::Job<lancedb::function::FunctionVersion>>,
}
/// Python bridge for a typed remote Function-column refresh job.
#[pyclass]
pub struct RefreshJob {
inner: Arc<lancedb::Job>,
}
impl FunctionJob {
pub(crate) fn new(inner: lancedb::Job<lancedb::function::FunctionVersion>) -> Self {
Self {
@@ -38,6 +44,56 @@ impl Job {
}
}
impl RefreshJob {
pub(crate) fn new(inner: lancedb::Job) -> Self {
Self {
inner: Arc::new(inner),
}
}
}
#[pymethods]
impl RefreshJob {
#[getter]
pub fn id(&self) -> Option<String> {
self.inner.id().map(str::to_string)
}
pub fn status(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner.clone();
future_into_py(
self_.py(),
async move { inner.status().await.infer_error() },
)
}
pub fn wait(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner.clone();
future_into_py(self_.py(), async move {
let value = inner.wait_raw_json().await.infer_error()?.ok_or_else(|| {
pyo3::exceptions::PyValueError::new_err(
"successful refresh job did not contain a result",
)
})?;
let result: lancedb::function::RefreshColumnResult = serde_json::from_value(value)
.map_err(|error| {
pyo3::exceptions::PyValueError::new_err(format!(
"invalid refresh job result: {error}"
))
})?;
result.to_canonical_json().infer_error()
})
}
pub fn cancel(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
let inner = self_.inner.clone();
future_into_py(self_.py(), async move {
inner.cancel().await.infer_error()?;
Ok(())
})
}
}
#[pymethods]
impl FunctionJob {
#[getter]
+1
View File
@@ -48,6 +48,7 @@ pub fn _lancedb(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Table>()?;
m.add_class::<crate::job::Job>()?;
m.add_class::<crate::job::FunctionJob>()?;
m.add_class::<crate::job::RefreshJob>()?;
m.add_class::<crate::job::JobInfo>()?;
m.add_class::<crate::job::JobDescription>()?;
m.add_class::<crate::job::JobFailureInfo>()?;
+1 -1
View File
@@ -1584,7 +1584,7 @@ impl Table {
let inner = self_.inner_ref()?.clone();
future_into_py(self_.py(), async move {
let job = inner.refresh_column_async(column).await.infer_error()?;
Ok(crate::job::Job::new(job))
Ok(crate::job::RefreshJob::new(job))
})
}