Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 0 additions & 18 deletions python/python/lance/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3575,24 +3575,6 @@ def to_stream_reader(self) -> pa.RecordBatchReader:
"""
return self._query.to_stream_reader()

def explain_plan(self, verbose: bool = False, analyze: bool = False) -> str:
"""
Explain the query plan.

Parameters
----------
verbose: bool, default False
If True, print the verbose plan.
analyze: bool, default False
If True, analyze the query and print the statistics.

Returns
-------
str
The query plan.
"""
return self._query.explain_plan(verbose, analyze)


Comment thread
yanghua marked this conversation as resolved.
class SqlQueryBuilder:
"""
Expand Down
5 changes: 5 additions & 0 deletions python/python/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4043,6 +4043,11 @@ def test_dataset_sql(tmp_path: Path):
expected = pa.table({"id": [2, 3], "value": ["b", "c"]})
assert pa.Table.from_batches(result) == expected

# Validate explain_plan() returns readable plan text and contains recognizable markers
plan_text = query.explain_plan()
assert isinstance(plan_text, str) and len(plan_text) > 0
assert any(tok in plan_text for tok in ["ProjectionExec", "LanceRead", "logical_plan", "Plan with Metrics"])

stream_result = (
ds.sql("SELECT value FROM test WHERE id = 1")
.table_name("test")
Expand Down
1 change: 0 additions & 1 deletion python/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,6 @@ impl SqlQuery {
Box::new(LanceReader::from_stream(dataset_stream));
Python::with_gil(|py| reader.into_pyarrow(py))
}
}

#[pyclass(name = "SqlQueryBuilder", module = "_lib", subclass)]
Comment thread
yanghua marked this conversation as resolved.
#[derive(Clone)]
Expand Down
2 changes: 2 additions & 0 deletions rust/lance/src/dataset/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

use crate::datafusion::LanceTableProvider;
use crate::Dataset;
use arrow_array::RecordBatch;

Check warning on line 6 in rust/lance/src/dataset/sql.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/lance/lance/rust/lance/src/dataset/sql.rs
use datafusion::dataframe::DataFrame;
use datafusion::execution::SendableRecordBatchStream;
use datafusion::prelude::SessionContext;
use datafusion::physical_plan::display::DisplayableExecutionPlan;
use lance_datafusion::exec::{analyze_plan, LanceExecutionOptions};
use futures::TryStreamExt;
use std::sync::Arc;

Expand Down
Loading