Skip to content

Commit a75bbc3

Browse files
committed
fix: address review feedback on JoinNode proto round-trip
- Drop `..` in encoder destructure; bind `schema: _` explicitly so any future field added to `Join` is a compile error here. This is the shape that allowed apache#22065 to slip through silently. - Reclassify the new key-length mismatch as a proto_error (malformed wire input) instead of internal_err, matching the surrounding decoder pattern. - Drop redundant execution + row-count checks from roundtrip_join_null_aware; Debug-equality already covers the field-preservation regression. - Rewrite roundtrip_join_null_equality to construct the Join directly via Join::try_new with NullEquality::NullEqualsNull set at construction, instead of SQL + optimizer + transform_up mutation.
1 parent 5ce8de0 commit a75bbc3

2 files changed

Lines changed: 34 additions & 56 deletions

File tree

‎datafusion/proto/src/logical_plan/mod.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,11 @@ impl AsLogicalPlan for LogicalPlanNode {
850850
let right_keys: Vec<Expr> =
851851
from_proto::parse_exprs(&join.right_join_key, ctx, extension_codec)?;
852852
if left_keys.len() != right_keys.len() {
853-
return internal_err!(
854-
"JoinNode: left_join_key and right_join_key must be the same length, got {} and {}",
853+
return Err(proto_error(format!(
854+
"Received a JoinNode message with left_join_key and right_join_key of different lengths: {} and {}",
855855
left_keys.len(),
856856
right_keys.len()
857-
);
857+
)));
858858
}
859859
let join_type =
860860
protobuf::JoinType::try_from(join.join_type).map_err(|_| {
@@ -1494,7 +1494,8 @@ impl AsLogicalPlan for LogicalPlanNode {
14941494
join_constraint,
14951495
null_equality,
14961496
null_aware,
1497-
..
1497+
// Not encoded; recomputed by `Join::try_new` on decode.
1498+
schema: _,
14981499
}) => {
14991500
let left: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
15001501
left.as_ref(),

‎datafusion/proto/tests/cases/roundtrip_logical_plan.rs‎

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,25 +3212,6 @@ async fn roundtrip_join_null_aware() -> Result<()> {
32123212
let logical_round_trip = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
32133213
assert_eq!(format!("{plan:?}"), format!("{logical_round_trip:?}"));
32143214

3215-
let direct: usize = ctx
3216-
.execute_logical_plan(plan)
3217-
.await?
3218-
.collect()
3219-
.await?
3220-
.iter()
3221-
.map(|b| b.num_rows())
3222-
.sum();
3223-
let rt: usize = ctx
3224-
.execute_logical_plan(logical_round_trip)
3225-
.await?
3226-
.collect()
3227-
.await?
3228-
.iter()
3229-
.map(|b| b.num_rows())
3230-
.sum();
3231-
assert_eq!(direct, 0);
3232-
assert_eq!(rt, direct);
3233-
32343215
Ok(())
32353216
}
32363217

@@ -3241,43 +3222,39 @@ async fn roundtrip_join_null_aware() -> Result<()> {
32413222
#[tokio::test]
32423223
async fn roundtrip_join_null_equality() -> Result<()> {
32433224
use datafusion_common::NullEquality;
3244-
use datafusion_common::tree_node::{Transformed, TreeNode, TreeNodeRecursion};
3245-
use datafusion_expr::logical_plan::Join;
3225+
use datafusion_expr::JoinType;
3226+
use datafusion_expr::logical_plan::{Join, JoinConstraint};
32463227

32473228
let ctx = SessionContext::new();
3248-
let sql = "
3249-
SELECT t1.a FROM (VALUES (1)) AS t1(a)
3250-
INNER JOIN (VALUES (1)) AS t2(b) ON t1.a = t2.b
3251-
";
3252-
let plan = ctx
3253-
.sql(sql)
3254-
.await?
3255-
.into_optimized_plan()?
3256-
.transform_up(|node| {
3257-
Ok(match node {
3258-
LogicalPlan::Join(j) => Transformed::yes(LogicalPlan::Join(Join {
3259-
null_equality: NullEquality::NullEqualsNull,
3260-
..j
3261-
})),
3262-
other => Transformed::no(other),
3263-
})
3264-
})?
3265-
.data;
32663229

3267-
let bytes = logical_plan_to_bytes(&plan)?;
3268-
let rt = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
3269-
assert_eq!(format!("{plan:?}"), format!("{rt:?}"));
3230+
let left_schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int32, true)]));
3231+
let right_schema =
3232+
Arc::new(Schema::new(vec![Field::new("b", DataType::Int32, true)]));
3233+
ctx.register_table(
3234+
"t1",
3235+
Arc::new(datafusion::datasource::empty::EmptyTable::new(left_schema)),
3236+
)?;
3237+
ctx.register_table(
3238+
"t2",
3239+
Arc::new(datafusion::datasource::empty::EmptyTable::new(right_schema)),
3240+
)?;
3241+
let left = ctx.table("t1").await?.into_optimized_plan()?;
3242+
let right = ctx.table("t2").await?.into_optimized_plan()?;
32703243

3271-
let mut found = false;
3272-
rt.apply(|n| {
3273-
if let LogicalPlan::Join(j) = n
3274-
&& j.null_equality == NullEquality::NullEqualsNull
3275-
{
3276-
found = true;
3277-
}
3278-
Ok(TreeNodeRecursion::Continue)
3279-
})?;
3280-
assert!(found);
3244+
let join = LogicalPlan::Join(Join::try_new(
3245+
Arc::new(left),
3246+
Arc::new(right),
3247+
vec![(col("t1.a"), col("t2.b"))],
3248+
None,
3249+
JoinType::Inner,
3250+
JoinConstraint::On,
3251+
NullEquality::NullEqualsNull,
3252+
false,
3253+
)?);
3254+
3255+
let bytes = logical_plan_to_bytes(&join)?;
3256+
let rt = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
3257+
assert_eq!(format!("{join:?}"), format!("{rt:?}"));
32813258

32823259
Ok(())
32833260
}

0 commit comments

Comments
 (0)