Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Feb 21, 2024
1 parent d8cec17 commit 0b316cb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
15 changes: 12 additions & 3 deletions optd-core/src/cascades/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use std::any::Any;
use crate::{
cost::Cost,
property::PropertyBuilderAny,
rel_node::{RelNode, RelNodeMeta, RelNodeMetaMap, RelNodeRef, RelNodeRefPtr, RelNodeTyp, Value},
rel_node::{
RelNode, RelNodeMeta, RelNodeMetaMap, RelNodeRef, RelNodeRefPtr, RelNodeTyp, Value,
},
};

use super::optimizer::{ExprId, GroupId};
Expand Down Expand Up @@ -441,7 +443,11 @@ impl<T: RelNodeTyp> Memo<T> {
}

/// Gets the best group binding with metadata collected.
pub fn get_best_group_binding_with_meta(&self, group_id: GroupId, meta: &mut RelNodeMetaMap<T>) -> Result<RelNodeRef<T>> {
pub fn get_best_group_binding_with_meta(
&self,
group_id: GroupId,
meta: &mut RelNodeMetaMap<T>,
) -> Result<RelNodeRef<T>> {
let info = self.get_group_info(group_id);
if let Some(winner) = info.winner {
if !winner.impossible {
Expand All @@ -450,7 +456,10 @@ impl<T: RelNodeTyp> Memo<T> {
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)?);
meta.insert(RelNodeRefPtr(children.last().unwrap()), RelNodeMeta::new(*child));
meta.insert(
RelNodeRefPtr(children.last().unwrap()),
RelNodeMeta::new(*child),
);
}
let node = Arc::new(RelNode {
typ: expr.typ.clone(),
Expand Down
6 changes: 5 additions & 1 deletion optd-core/src/cascades/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl<T: RelNodeTyp> CascadesOptimizer<T> {
Ok(group_id)
}

pub fn step_get_optimize_rel_with_meta(&self, group_id: GroupId, meta: &mut RelNodeMetaMap<T>) -> Result<RelNodeRef<T>> {
pub fn step_get_optimize_rel_with_meta(
&self,
group_id: GroupId,
meta: &mut RelNodeMetaMap<T>,
) -> Result<RelNodeRef<T>> {
let rel = self.memo.get_best_group_binding_with_meta(group_id, meta)?;
meta.insert(RelNodeRefPtr(&rel), RelNodeMeta::new(group_id));
Ok(rel)
Expand Down
7 changes: 5 additions & 2 deletions optd-core/src/rel_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//! the internal representation of the plan nodes.

use std::{
collections::HashMap, fmt::{Debug, Display}, hash::Hash, sync::Arc
collections::HashMap,
fmt::{Debug, Display},
hash::Hash,
sync::Arc,
};

use ordered_float::OrderedFloat;
Expand Down Expand Up @@ -203,7 +206,7 @@ impl RelNodeMeta {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RelNodeRefPtr<T: RelNodeTyp>(pub * const RelNodeRef<T>);
pub struct RelNodeRefPtr<T: RelNodeTyp>(pub *const RelNodeRef<T>);

unsafe impl<T: RelNodeTyp> Send for RelNodeRefPtr<T> {}

Expand Down
2 changes: 1 addition & 1 deletion optd-datafusion-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl OptdQueryPlanner {
let mut optimizer = self.optimizer.lock().unwrap().take().unwrap();
let (group_id, optimized_rel, meta) = optimizer.optimize(optd_rel)?;

meta.iter().for_each(|(k,v)| {
meta.iter().for_each(|(k, v)| {
println!("(rel@{:?}, group_id={:?})", k, v);
});

Expand Down

0 comments on commit 0b316cb

Please sign in to comment.