Skip to content

Commit 9e6fce9

Browse files
Kanishk SachanCopilot
andcommitted
test(proto): add roundtrip test for UnKnownColumn; fix fragile float equality in binary statistics test
Closes: address requested roundtrip test and stabilize failing test Co-authored-by: Copilot <[email protected]>
1 parent dd1fa5c commit 9e6fce9

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎datafusion/physical-expr/src/expressions/binary.rs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,10 +4889,22 @@ mod tests {
48894889
);
48904890

48914891
// The probability of being distinct is 1 - 1 / 16 = 15 / 16.
4892-
assert_eq!(
4893-
neq.evaluate_statistics(&[left_stat, right_stat])?,
4894-
Distribution::new_bernoulli(ScalarValue::from(15.0 / 16.0))?
4895-
);
4892+
let got = neq.evaluate_statistics(&[left_stat, right_stat])?;
4893+
let expected = Distribution::new_bernoulli(ScalarValue::from(15.0 / 16.0))?;
4894+
match (got, expected) {
4895+
(Bernoulli(g), Bernoulli(e)) => {
4896+
let gp = match g.p_value() {
4897+
ScalarValue::Float64(Some(v)) => v,
4898+
_ => panic!("got unexpected p type"),
4899+
};
4900+
let ep = match e.p_value() {
4901+
ScalarValue::Float64(Some(v)) => v,
4902+
_ => panic!("expected unexpected p type"),
4903+
};
4904+
assert!((gp - ep).abs() < 1e-12);
4905+
}
4906+
_ => panic!("unexpected distribution variants"),
4907+
}
48964908

48974909
Ok(())
48984910
}

‎datafusion/physical-expr/src/expressions/unknown_column.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,26 @@ mod tests {
196196
assert!(err.contains("expr_id=Some(7)"));
197197
assert!(err.contains("PhysicalColumn"));
198198
}
199+
200+
#[cfg(feature = "proto")]
201+
#[test]
202+
fn unknown_column_proto_roundtrip() {
203+
use datafusion_proto_models::protobuf;
204+
205+
let name = "col_b".to_string();
206+
let node = protobuf::PhysicalExprNode {
207+
expr_id: Some(42),
208+
expr_type: Some(protobuf::physical_expr_node::ExprType::UnknownColumn(
209+
protobuf::UnknownColumn { name: name.clone() },
210+
)),
211+
};
212+
213+
let schema = Schema::empty();
214+
let decoder = DummyDecode;
215+
let ctx = PhysicalExprDecodeCtx::new(&schema, &decoder);
216+
217+
let decoded = UnKnownColumn::try_from_proto(&node, &ctx).unwrap();
218+
let col = decoded.as_ref().downcast_ref::<UnKnownColumn>().unwrap();
219+
assert_eq!(col.name(), name.as_str());
220+
}
199221
}

0 commit comments

Comments
 (0)