Skip to content

Commit 6311fa3

Browse files
better assertions
1 parent c042c08 commit 6311fa3

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

datafusion/proto/src/physical_plan/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,13 +3885,7 @@ impl PhysicalProtoConverterExtension for DeduplicatingDeserializer {
38853885
let mut cache = self.cache.borrow_mut();
38863886
if let Some(cached) = cache.get(&id) {
38873887
let children: Vec<_> = parsed.children().into_iter().cloned().collect();
3888-
let cached_children: Vec<_> =
3889-
cached.children().into_iter().cloned().collect();
3890-
return if children == cached_children {
3891-
Ok(Arc::clone(cached))
3892-
} else {
3893-
Arc::clone(cached).with_new_children(children)
3894-
};
3888+
return Arc::clone(cached).with_new_children(children);
38953889
}
38963890

38973891
cache.insert(id, Arc::clone(&parsed));

datafusion/proto/tests/cases/roundtrip_physical_plan.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,21 +2877,38 @@ fn assert_dynamic_filter_update_is_visible(
28772877
Ok(())
28782878
}
28792879

2880+
/// Assert that the actual dynamic filter snapshot matches the expected one
2881+
/// after roundtrip.
28802882
fn assert_dynamic_filter_snapshot_matches(
28812883
expected: &Arc<dyn PhysicalExpr>,
28822884
actual: &Arc<dyn PhysicalExpr>,
28832885
) {
2884-
let expected = expected
2886+
let expected_filter = expected
28852887
.downcast_ref::<DynamicFilterPhysicalExpr>()
28862888
.expect("Expected dynamic filter");
2887-
let actual = actual
2889+
let actual_filter = actual
28882890
.downcast_ref::<DynamicFilterPhysicalExpr>()
28892891
.expect("Expected dynamic filter");
28902892

2891-
assert_eq!(
2892-
DynamicFilterSnapshot::from(expected).to_string(),
2893-
DynamicFilterSnapshot::from(actual).to_string(),
2894-
);
2893+
let actual_snapshot = DynamicFilterSnapshot::from(actual_filter).to_string();
2894+
let expected_snapshot = DynamicFilterSnapshot::from(expected_filter).to_string();
2895+
if expected_snapshot == actual_snapshot {
2896+
return;
2897+
}
2898+
2899+
// Note that the `DeduplicatingDeserializer` routes every cache hit through
2900+
// `with_new_children`. This produces an equivalent expression, but with
2901+
// remapped children that are equal to the original. Handle that case here.
2902+
let rewritten = Arc::clone(expected)
2903+
.with_new_children(expected.children().iter().map(|c| Arc::clone(c)).collect())
2904+
.expect("with_new_children on a dynamic filter should not fail");
2905+
let rewritten_snapshot = DynamicFilterSnapshot::from(
2906+
rewritten
2907+
.downcast_ref::<DynamicFilterPhysicalExpr>()
2908+
.expect("with_new_children returns a DynamicFilterPhysicalExpr"),
2909+
)
2910+
.to_string();
2911+
assert_eq!(rewritten_snapshot, actual_snapshot);
28952912
}
28962913

28972914
// Two clones of a dynamic filter expression should be deduped to the exact same expression.
@@ -2943,19 +2960,6 @@ fn test_dynamic_filter_plan_roundtrip_dedupe() -> Result<()> {
29432960
) = roundtrip_dynamic_filter_plan_pair()?;
29442961

29452962
// Assert the filters are not modified during roundtrip.
2946-
//
2947-
// There's a small technicality that `filter_expr_1` is rewritten to an equivalent expression
2948-
// during deserialization, so we capture that here by calling
2949-
// `filter.with_new_children(filter.children)`.
2950-
let filter_expr_1_children = Arc::clone(&filter_expr_1)
2951-
.children()
2952-
.iter()
2953-
.map(|child| Arc::clone(child))
2954-
.collect::<Vec<_>>();
2955-
let filter_expr_1 = filter_expr_1
2956-
.clone()
2957-
.with_new_children(filter_expr_1_children)
2958-
.unwrap();
29592963
assert_dynamic_filter_snapshot_matches(
29602964
&filter_expr_1,
29612965
&filter_expr_1_after_roundtrip,

0 commit comments

Comments
 (0)