mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
Expose the durable SQL registry id separately from the connection-scoped query UUID. Rust and Python query handles and descriptions expose optional `job_id`; result readers preserve it in schema metadata under `x-lancedb-sql-job-id`, without adding business columns. Clients can reopen that id with `open_job`. Poll success and failure metadata update the same handle. A failure before the first successful poll retains its job id and original structured error. The cancellation documentation distinguishes the Flight waiter from `cancel_job(job_id)`. Validation on the designated EC2: the two focused error interoperability tests and Ruff passed on `a8798e81`; delivery has the identical tree. The preceding 51 Rust SQL tests and earlier 31 native Python SQL tests are reused for unchanged coverage. Matching-runtime independent acceptance remains pending. Companion server change: https://github.com/lancedb/sophon/pull/10049. Refs ENT-3562.
98 lines
2.5 KiB
Rust
98 lines
2.5 KiB
Rust
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
use std::sync::Arc;
|
|
|
|
use chrono::{DateTime, Utc};
|
|
use pyo3::{Bound, PyAny, PyRef, PyResult, pyclass, pymethods};
|
|
use uuid::Uuid;
|
|
|
|
use crate::arrow::RecordBatchStream;
|
|
use crate::error::PythonErrorExt;
|
|
use crate::runtime::future_into_py;
|
|
|
|
#[pyclass(name = "SqlQuery")]
|
|
pub struct Query {
|
|
inner: Arc<lancedb::sql::Query>,
|
|
}
|
|
|
|
impl Query {
|
|
pub(crate) fn new(inner: lancedb::sql::Query) -> Self {
|
|
Self {
|
|
inner: Arc::new(inner),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[pymethods]
|
|
impl Query {
|
|
#[getter]
|
|
pub fn id(&self) -> Uuid {
|
|
self.inner.id()
|
|
}
|
|
|
|
#[getter]
|
|
pub fn job_id(&self) -> Option<String> {
|
|
self.inner.job_id()
|
|
}
|
|
|
|
pub fn describe(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
|
let inner = self_.inner.clone();
|
|
future_into_py(self_.py(), async move {
|
|
inner
|
|
.describe()
|
|
.await
|
|
.map(QueryDescription::from)
|
|
.infer_error()
|
|
})
|
|
}
|
|
|
|
pub fn reader(self_: PyRef<'_, Self>) -> PyResult<Bound<'_, PyAny>> {
|
|
let inner = self_.inner.clone();
|
|
future_into_py(self_.py(), async move {
|
|
let stream = inner.reader().await.infer_error()?;
|
|
Ok(RecordBatchStream::new(stream))
|
|
})
|
|
}
|
|
|
|
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(())
|
|
})
|
|
}
|
|
}
|
|
|
|
#[pyclass(get_all, skip_from_py_object)]
|
|
#[derive(Clone)]
|
|
pub struct QueryDescription {
|
|
id: Uuid,
|
|
job_id: Option<String>,
|
|
status: String,
|
|
progress: Option<f64>,
|
|
expires_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[pymethods]
|
|
impl QueryDescription {
|
|
fn __repr__(&self) -> String {
|
|
format!(
|
|
"QueryDescription(id={:?}, job_id={:?}, status={:?}, progress={:?}, expires_at={:?})",
|
|
self.id, self.job_id, self.status, self.progress, self.expires_at
|
|
)
|
|
}
|
|
}
|
|
|
|
impl From<lancedb::sql::QueryDescription> for QueryDescription {
|
|
fn from(description: lancedb::sql::QueryDescription) -> Self {
|
|
Self {
|
|
id: description.id,
|
|
job_id: description.job_id,
|
|
status: description.status.to_string(),
|
|
progress: description.progress,
|
|
expires_at: description.expires_at,
|
|
}
|
|
}
|
|
}
|