Skip to content

Commit b8c6f6e

Browse files
committed
cleanup + add comments
1 parent 6a25f04 commit b8c6f6e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/daft-sql/src/planner.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ impl<'a> SQLPlanner<'a> {
144144
}
145145
}
146146

147+
/// Set `self.current_plan`. Should only be called once per query.
148+
fn set_plan(&mut self, plan: LogicalPlanBuilder) {
149+
assert!(self.current_plan.is_none());
150+
151+
self.current_plan = Some(plan);
152+
}
153+
147154
fn update_plan<E>(
148155
&mut self,
149156
f: impl FnOnce(&LogicalPlanBuilder) -> Result<LogicalPlanBuilder, E>,
@@ -672,7 +679,7 @@ impl<'a> SQLPlanner<'a> {
672679
let relation = from.relation.clone();
673680
let left_plan = self.plan_relation(&relation)?;
674681
let mut left_planner = self.new_with_context();
675-
left_planner.current_plan = Some(left_plan);
682+
left_planner.set_plan(left_plan);
676683

677684
for join in &from.joins {
678685
use sqlparser::ast::{
@@ -689,7 +696,7 @@ impl<'a> SQLPlanner<'a> {
689696

690697
// construct a planner with the right table to use for expr planning
691698
let mut right_planner = self.new_with_context();
692-
right_planner.current_plan = Some(right_plan);
699+
right_planner.set_plan(right_plan);
693700

694701
let (join_type, constraint) = match &join.join_operator {
695702
Inner(constraint) => (JoinType::Inner, constraint),
@@ -761,7 +768,7 @@ impl<'a> SQLPlanner<'a> {
761768
Ok(left_planner.current_plan.unwrap())
762769
}
763770

764-
/// Plans the FROM clause of a query and populates self.current_relation and self.table_map
771+
/// Plans the FROM clause of a query and populates `self.current_relation`.
765772
/// Should only be called once per query.
766773
fn plan_from(&mut self, from: &[TableWithJoins]) -> SQLPlannerResult<()> {
767774
let plan = if let Some(plan) = from
@@ -782,10 +789,11 @@ impl<'a> SQLPlanner<'a> {
782789
{
783790
plan
784791
} else {
792+
// singleton plan for SELECT without FROM
785793
singleton_plan()?
786794
};
787795

788-
self.current_plan = Some(plan);
796+
self.set_plan(plan);
789797

790798
Ok(())
791799
}

0 commit comments

Comments
 (0)