feat: add the explain_plan function (#1328)

It's useful to see the underlying query plan for debugging purposes.
This exposes LanceScanner's `explain_plan` function. Addresses #1288

---------

Co-authored-by: Will Jones <willjones127@gmail.com>
This commit is contained in:
Nuvic
2024-07-02 11:10:01 -07:00
committed by GitHub
parent 12b3c87964
commit 46c6ff889d
9 changed files with 226 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ use lancedb::query::QueryExecutionOptions;
use lancedb::query::{
ExecutableQuery, Query as LanceDbQuery, QueryBase, Select, VectorQuery as LanceDbVectorQuery,
};
use pyo3::exceptions::PyRuntimeError;
use pyo3::pyclass;
use pyo3::pymethods;
use pyo3::PyAny;
@@ -73,6 +74,16 @@ impl Query {
Ok(RecordBatchStream::new(inner_stream))
})
}
fn explain_plan(self_: PyRef<'_, Self>, verbose: bool) -> PyResult<&PyAny> {
let inner = self_.inner.clone();
future_into_py(self_.py(), async move {
inner
.explain_plan(verbose)
.await
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
})
}
}
#[pyclass]
@@ -131,4 +142,14 @@ impl VectorQuery {
Ok(RecordBatchStream::new(inner_stream))
})
}
fn explain_plan(self_: PyRef<'_, Self>, verbose: bool) -> PyResult<&PyAny> {
let inner = self_.inner.clone();
future_into_py(self_.py(), async move {
inner
.explain_plan(verbose)
.await
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
})
}
}