Skip to content

Commit c15f1ca

Browse files
committed
refactor(cubesql): Extract QueryPlan::try_as_logical_plan
1 parent 4de8e9a commit c15f1ca

File tree

1 file changed

+10
-5
lines changed
  • rust/cubesql/cubesql/src/compile

1 file changed

+10
-5
lines changed

rust/cubesql/cubesql/src/compile/plan.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,22 @@ impl fmt::Debug for QueryPlan {
7878
}
7979

8080
impl QueryPlan {
81-
pub fn as_logical_plan(&self) -> LogicalPlan {
81+
pub fn try_as_logical_plan(&self) -> Result<&LogicalPlan, CubeError> {
8282
match self {
8383
QueryPlan::DataFusionSelect(plan, _) | QueryPlan::CreateTempTable(plan, _, _, _) => {
84-
plan.clone()
85-
}
86-
QueryPlan::MetaOk(_, _) | QueryPlan::MetaTabular(_, _) => {
87-
panic!("This query doesnt have a plan, because it already has values for response")
84+
Ok(plan)
8885
}
86+
QueryPlan::MetaOk(_, _) | QueryPlan::MetaTabular(_, _) => Err(CubeError::internal(
87+
"This query doesnt have a plan, because it already has values for response"
88+
.to_string(),
89+
)),
8990
}
9091
}
9192

93+
pub fn as_logical_plan(&self) -> LogicalPlan {
94+
self.try_as_logical_plan().cloned().unwrap()
95+
}
96+
9297
pub async fn as_physical_plan(&self) -> Result<Arc<dyn ExecutionPlan>, CubeError> {
9398
match self {
9499
QueryPlan::DataFusionSelect(plan, ctx)

0 commit comments

Comments
 (0)