use std::any::Any;
use std::collections::BTreeMap;
use lora_compiler::plan_tree_from_compiled;
use lora_executor::{classify_stream, plan_result_columns, LoraValue};
use lora_store::{GraphStorage, GraphStorageMut};
use crate::database::Database;
use crate::error::LoraError;
use crate::explain::{PlanShape, QueryPlan};
impl<S> Database<S>
where
S: GraphStorage + GraphStorageMut + Any + Clone + Send + Sync + 'static,
{
pub fn explain(
&self,
query: &str,
_params: Option<BTreeMap<String, LoraValue>>,
) -> Result<QueryPlan, LoraError> {
let store = self.read_store();
let compiled = self
.compile_query_cached(query, &*store)
.map_err(LoraError::from_anyhow)?;
let tree = plan_tree_from_compiled(&compiled);
let shape: PlanShape = classify_stream(&compiled).into();
let result_columns = plan_result_columns(&compiled.physical);
Ok(QueryPlan {
query: query.to_string(),
tree,
shape,
result_columns,
})
}
}