Skip to content

Commit

Permalink
move collector logic to bridge
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Mar 11, 2024
1 parent da87d14 commit 20fa55d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
31 changes: 0 additions & 31 deletions optd-core/src/cascades/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,37 +495,6 @@ impl<T: RelNodeTyp> Memo<T> {
grp.unwrap().info = group_info;
}

/// Gets the best group binding with metadata collected.
pub fn get_best_group_binding_with_meta(
&self,
group_id: GroupId,
meta: &mut RelNodeMetaMap,
) -> Result<RelNodeRef<T>> {
let info = self.get_group_info(group_id);
if let Some(winner) = info.winner {
if !winner.impossible {
let expr_id = winner.expr_id;
let expr = self.get_expr_memoed(expr_id);
let mut children = Vec::with_capacity(expr.children.len());
for child in &expr.children {
children.push(self.get_best_group_binding_with_meta(*child, meta)?);
}
let node = Arc::new(RelNode {
typ: expr.typ.clone(),
children,
data: expr.data.clone(),
});

meta.insert(
node.as_ref() as *const _ as usize,
RelNodeMeta::new(group_id),
);
return Ok(node);
}
}
bail!("no best group binding for group {}", group_id)
}

pub fn get_best_group_binding(
&self,
group_id: GroupId,
Expand Down
2 changes: 1 addition & 1 deletion optd-core/src/cascades/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
cost::CostModel,
optimizer::Optimizer,
property::{PropertyBuilder, PropertyBuilderAny},
rel_node::{RelNodeMeta, RelNodeMetaMap, RelNodeRef, RelNodeTyp},
rel_node::{RelNodeMetaMap, RelNodeRef, RelNodeTyp},
rules::RuleWrapper,
};

Expand Down
2 changes: 2 additions & 0 deletions optd-core/src/rel_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ impl<T: RelNodeTyp> RelNode<T> {
}
}

/// Metadata for a rel node.
#[derive(Clone, Debug, PartialEq)]
pub struct RelNodeMeta {
/// The group (id) of the `RelNode`
pub group_id: GroupId,
}

Expand Down
19 changes: 12 additions & 7 deletions optd-datafusion-bridge/src/from_optd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,18 @@ impl OptdPlanContext<'_> {
typ => unimplemented!("{}", typ),
};

let bare_with_collector: Result<Arc<dyn ExecutionPlan>> = Ok(Arc::new(CollectorExec::new(
bare,
group_id,
self.optimizer.as_ref().unwrap().runtime_statistics.clone(),
))
as Arc<dyn ExecutionPlan>);
bare_with_collector.with_context(|| format!("when processing {}", rel_node_dbg))
let optimizer = self.optimizer.as_ref().unwrap();
if optimizer.adaptive_enabled() {
let bare_with_collector: Result<Arc<dyn ExecutionPlan>> =
Ok(Arc::new(CollectorExec::new(
bare,
group_id,
self.optimizer.as_ref().unwrap().runtime_statistics.clone(),
)) as Arc<dyn ExecutionPlan>);
bare_with_collector.with_context(|| format!("when processing {}", rel_node_dbg))
} else {
Ok(bare)
}
}

pub async fn conv_from_optd(
Expand Down
4 changes: 4 additions & 0 deletions optd-datafusion-repr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl DatafusionOptimizer {
self.enable_adaptive = enable;
}

pub fn adaptive_enabled(&self) -> bool {
self.enable_adaptive
}

pub fn optd_optimizer(&self) -> &CascadesOptimizer<OptRelNodeTyp> {
&self.optimizer
}
Expand Down

0 comments on commit 20fa55d

Please sign in to comment.