Skip to content

Commit

Permalink
chore: Clean up join order iteration (#3638)
Browse files Browse the repository at this point in the history
Missed a comment to
#3616 (comment):
```
In [src/daft-logical-plan/src/optimization/rules/reorder_joins/join_graph.rs](#3616 (comment)):

>  };
 
-#[derive(Debug)]
-struct JoinNode {
+// TODO(desmond): In the future these trees should keep track of current cost estimates.
+#[derive(Clone, Debug)]
+pub(super) enum JoinOrderTree {
+    Relation(usize),                                          // (id).
+    Join(Box<JoinOrderTree>, Box<JoinOrderTree>, Vec<usize>), // (subtree, subtree, nodes involved).
I dont think you need to keep an explicit stack. I think you should be able to something like

std::iter::chain(left.into_iter(), right.into_iter())
```

This PR removes the stack and simply chains the iterators.
  • Loading branch information
desmondcheongzx authored Jan 6, 2025
1 parent fc497fd commit 2aac957
Showing 1 changed file with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,11 @@ impl JoinOrderTree {
}
}

pub(super) fn iter(&self) -> JoinOrderTreeIterator {
JoinOrderTreeIterator { stack: vec![self] }
}
}

pub(super) struct JoinOrderTreeIterator<'a> {
stack: Vec<&'a JoinOrderTree>,
}

impl<'a> Iterator for JoinOrderTreeIterator<'a> {
type Item = usize;

fn next(&mut self) -> Option<Self::Item> {
while let Some(node) = self.stack.pop() {
match node {
JoinOrderTree::Relation(id) => return Some(*id),
JoinOrderTree::Join(left, right) => {
self.stack.push(left);
self.stack.push(right);
}
}
fn iter(&self) -> Box<dyn Iterator<Item = usize> + '_> {
match self {
JoinOrderTree::Relation(id) => Box::new(std::iter::once(*id)),
JoinOrderTree::Join(left, right) => Box::new(left.iter().chain(right.iter())),
}
None
}
}

Expand Down

0 comments on commit 2aac957

Please sign in to comment.