Skip to content

Commit

Permalink
t.transformed test
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Feb 1, 2024
1 parent 84d91c6 commit d2c84ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions datafusion/common/src/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use std::sync::Arc;

use crate::utils::DataPtr;

use crate::Result;

/// If the function returns [`TreeNodeRecursion::Continue`], the normal execution of the
Expand Down Expand Up @@ -479,7 +481,17 @@ impl<T: DynTreeNode + ?Sized> TreeNode for Arc<T> {
let children = self.arc_children();
if !children.is_empty() {
let t = children.into_iter().map_till_continue_and_collect(f)?;

// TODO: once we trust `t.transformed` don't create new node if not necessary
let old_children = self.arc_children();
assert_eq!(
t.transformed,
t.data
.iter()
.zip(old_children.iter())
.any(|(c1, c2)| !Arc::data_ptr_eq(c1, c2))
);

let arc_self = Arc::clone(&self);
self.with_new_arc_children(arc_self, t.data)
} else {
Expand Down
9 changes: 6 additions & 3 deletions datafusion/expr/src/tree_node/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ impl TreeNode for LogicalPlan {
.iter()
.map(|c| (*c).clone())
.map_till_continue_and_collect(f)?;

// TODO: once we trust `t.transformed` remove additional check
if old_children
let transformed = old_children
.into_iter()
.zip(t.data.iter())
.any(|(c1, c2)| c1 != c2)
{
.any(|(c1, c2)| c1 != c2);
assert_eq!(t.transformed, transformed);

if transformed {
Ok(Transformed::new(
self.with_new_exprs(self.expressions(), t.data)?,
true,
Expand Down

0 comments on commit d2c84ea

Please sign in to comment.