Skip to content

Apache DataFusion SQL Query Engine

refactor(proto): destructure plan and proto structs in join serde hooks (#24164)

Adrian Garcia Badaracco206813fb1da5
diff --git a/datafusion/physical-plan/src/joins/cross_join.rs b/datafusion/physical-plan/src/joins/cross_join.rs
index 3e798573f5..e4dbbdf628 100644
--- a/datafusion/physical-plan/src/joins/cross_join.rs
+++ b/datafusion/physical-plan/src/joins/cross_join.rs
@@ -462,8 +462,23 @@ impl ExecutionPlan for CrossJoinExec {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
use datafusion_proto_models::protobuf;
- let left = ctx.encode_child(self.left())?;
- let right = ctx.encode_child(self.right())?;
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ left,
+ right,
+ // derived from the children's schemas by `new` on decode
+ schema: _,
+ // runtime build-side state, not part of the plan
+ left_fut: _,
+ // runtime metrics, not part of the plan
+ metrics: _,
+ // recomputed by `new` on decode
+ cache: _,
+ } = self;
+
+ let left = ctx.encode_child(left)?;
+ let right = ctx.encode_child(right)?;
Ok(Some(protobuf::PhysicalPlanNode {
physical_plan_type: Some(
@@ -492,16 +507,13 @@ impl CrossJoinExec {
"CrossJoinExec",
);
- let left = ctx.decode_required_child(
- crossjoin.left.as_deref(),
- "CrossJoinExec",
- "left",
- )?;
- let right = ctx.decode_required_child(
- crossjoin.right.as_deref(),
- "CrossJoinExec",
- "right",
- )?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::CrossJoinExecNode { left, right } = &**crossjoin;
+
+ let left = ctx.decode_required_child(left.as_deref(), "CrossJoinExec", "left")?;
+ let right =
+ ctx.decode_required_child(right.as_deref(), "CrossJoinExec", "right")?;
Ok(Arc::new(CrossJoinExec::new(left, right)))
}
diff --git a/datafusion/physical-plan/src/joins/hash_join/exec.rs b/datafusion/physical-plan/src/joins/hash_join/exec.rs
index 5506199cb3..aa06015be7 100644
--- a/datafusion/physical-plan/src/joins/hash_join/exec.rs
+++ b/datafusion/physical-plan/src/joins/hash_join/exec.rs
@@ -1859,11 +1859,39 @@ impl ExecutionPlan for HashJoinExec {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
use datafusion_proto_models::protobuf;
- let left = ctx.encode_child(self.left())?;
- let right = ctx.encode_child(self.right())?;
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ left,
+ right,
+ on,
+ filter,
+ join_type,
+ mode,
+ projection,
+ null_equality,
+ null_aware,
+ dynamic_filter,
+ fetch,
+ // derived from the children's schemas by the builder on decode
+ join_schema: _,
+ // runtime build-side state, not part of the plan
+ left_fut: _,
+ // the fixed `HASH_JOIN_SEED` constant, set identically by the
+ // builder on decode
+ random_state: _,
+ // runtime metrics, not part of the plan
+ metrics: _,
+ // recomputed by the builder on decode
+ column_indices: _,
+ // recomputed by the builder on decode
+ cache: _,
+ } = self;
+
+ let left = ctx.encode_child(left)?;
+ let right = ctx.encode_child(right)?;
- let on = self
- .on()
+ let on = on
.iter()
.map(|(l, r)| -> Result<protobuf::JoinOn> {
Ok(protobuf::JoinOn {
@@ -1873,27 +1901,28 @@ impl ExecutionPlan for HashJoinExec {
})
.collect::<Result<Vec<_>>>()?;
- let join_type = crate::joins::proto::join_type_to_proto(*self.join_type());
- let null_equality =
- crate::joins::proto::null_equality_to_proto(self.null_equality());
+ let join_type = crate::joins::proto::join_type_to_proto(*join_type);
+ let null_equality = crate::joins::proto::null_equality_to_proto(*null_equality);
// `PartitionMode` is specific to `HashJoinExec`, so its conversion stays
// inline (by-name on purpose: the enums are numbered differently).
- let partition_mode = match self.partition_mode() {
+ let partition_mode = match mode {
PartitionMode::CollectLeft => protobuf::PartitionMode::CollectLeft,
PartitionMode::Partitioned => protobuf::PartitionMode::Partitioned,
PartitionMode::Auto => protobuf::PartitionMode::Auto,
};
- let filter = self
- .filter()
+ let filter = filter
+ .as_ref()
.map(|f| crate::joins::proto::join_filter_to_proto(f, ctx))
.transpose()?;
- let dynamic_filter = self
- .dynamic_expressions_produced()
- .into_iter()
- .next()
- .map(|expr| ctx.encode_expr(&expr))
+ let dynamic_filter = dynamic_filter
+ .as_ref()
+ .map(|df| {
+ let df_expr: Arc<dyn PhysicalExpr> =
+ Arc::clone(&df.filter) as Arc<dyn PhysicalExpr>;
+ ctx.encode_expr(&df_expr)
+ })
.transpose()?;
Ok(Some(protobuf::PhysicalPlanNode {
@@ -1914,14 +1943,14 @@ impl ExecutionPlan for HashJoinExec {
// single-element sentinel `[u32::MAX]` (never a valid column
// index); every other state is sent as-is. See
// `try_from_proto` for the matching decoder.
- projection: match self.projection.as_ref() {
+ projection: match projection.as_ref() {
None => Vec::new(),
Some(v) if v.is_empty() => vec![u32::MAX],
Some(v) => v.iter().map(|x| *x as u32).collect(),
},
- null_aware: self.null_aware,
+ null_aware: *null_aware,
dynamic_filter,
- fetch: self.fetch.map(|f| f as u64),
+ fetch: fetch.map(|f| f as u64),
},
)),
),
@@ -1946,18 +1975,29 @@ impl HashJoinExec {
"HashJoinExec",
);
- let left =
- ctx.decode_required_child(hashjoin.left.as_deref(), "HashJoinExec", "left")?;
- let right = ctx.decode_required_child(
- hashjoin.right.as_deref(),
- "HashJoinExec",
- "right",
- )?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::HashJoinExecNode {
+ left,
+ right,
+ on,
+ join_type,
+ partition_mode,
+ null_equality,
+ filter,
+ projection,
+ null_aware,
+ dynamic_filter,
+ fetch,
+ } = &**hashjoin;
+
+ let left = ctx.decode_required_child(left.as_deref(), "HashJoinExec", "left")?;
+ let right =
+ ctx.decode_required_child(right.as_deref(), "HashJoinExec", "right")?;
let left_schema = left.schema();
let right_schema = right.schema();
- let on: Vec<(PhysicalExprRef, PhysicalExprRef)> = hashjoin
- .on
+ let on: Vec<(PhysicalExprRef, PhysicalExprRef)> = on
.iter()
.map(|col| {
let l = ctx.decode_required_expr(
@@ -1976,38 +2016,32 @@ impl HashJoinExec {
})
.collect::<Result<_>>()?;
- let join_type = crate::joins::proto::join_type_from_proto(
- hashjoin.join_type,
- "HashJoinExec",
- )?;
+ let join_type =
+ crate::joins::proto::join_type_from_proto(*join_type, "HashJoinExec")?;
let null_equality = crate::joins::proto::null_equality_from_proto(
- hashjoin.null_equality,
+ *null_equality,
"HashJoinExec",
)?;
// `PartitionMode` is specific to `HashJoinExec`, so its conversion stays
// inline (by-name on purpose: the enums are numbered differently).
- let partition_mode = match protobuf::PartitionMode::try_from(
- hashjoin.partition_mode,
- )
- .map_err(|_| {
- internal_datafusion_err!(
- "HashJoinExec: unknown PartitionMode {}",
- hashjoin.partition_mode
- )
- })? {
+ let partition_mode = match protobuf::PartitionMode::try_from(*partition_mode)
+ .map_err(|_| {
+ internal_datafusion_err!(
+ "HashJoinExec: unknown PartitionMode {partition_mode}"
+ )
+ })? {
protobuf::PartitionMode::CollectLeft => PartitionMode::CollectLeft,
protobuf::PartitionMode::Partitioned => PartitionMode::Partitioned,
protobuf::PartitionMode::Auto => PartitionMode::Auto,
};
- let filter = hashjoin
- .filter
+ let filter = filter
.as_ref()
.map(|f| crate::joins::proto::join_filter_from_proto(f, ctx, "HashJoinExec"))
.transpose()?;
// Preserve the empty-projection sentinel written by `try_to_proto`.
- let projection = match hashjoin.projection.as_slice() {
+ let projection = match projection.as_slice() {
[] => None,
[u32::MAX] => Some(Vec::new()),
indices => Some(indices.iter().map(|i| *i as usize).collect()),
@@ -2023,8 +2057,7 @@ impl HashJoinExec {
// wrong limit but the worst one, silently turning the query into an
// empty result. Report the out-of-range value instead. Please do not
// "simplify" this back to `as usize`.
- let fetch = hashjoin
- .fetch
+ let fetch = fetch
.map(|f| {
usize::try_from(f).map_err(|_| {
plan_datafusion_err!(
@@ -2039,11 +2072,11 @@ impl HashJoinExec {
.with_projection(projection)
.with_partition_mode(partition_mode)
.with_null_equality(null_equality)
- .with_null_aware(hashjoin.null_aware)
+ .with_null_aware(*null_aware)
.with_fetch(fetch)
.build()?;
- if let Some(dynamic_filter_proto) = &hashjoin.dynamic_filter {
+ if let Some(dynamic_filter_proto) = dynamic_filter {
// The dynamic filter is a `DynamicFilterPhysicalExpr` over the probe
// (right) side; decode against the right schema then downcast.
let dynamic_filter_expr =
diff --git a/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs b/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs
index 60a25fc2ef..1ff2587ae8 100644
--- a/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs
+++ b/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs
@@ -208,14 +208,25 @@ impl PhysicalExpr for HashExpr {
ctx: &datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx<'_>,
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>> {
use datafusion_proto_models::protobuf;
- let on_columns = ctx.encode_children_expressions(&self.on_columns)?;
+
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ on_columns,
+ random_state,
+ description,
+ } = self;
+
+ let on_columns = ctx.encode_children_expressions(on_columns)?;
Ok(Some(protobuf::PhysicalExprNode {
expr_id: None,
expr_type: Some(protobuf::physical_expr_node::ExprType::HashExpr(
protobuf::PhysicalHashExprNode {
on_columns,
- seed0: self.seed(),
- description: self.description.clone(),
+ // only the seed is serialized; `RandomState` is rebuilt
+ // from it by `SeededRandomState::with_seed` on decode
+ seed0: random_state.seed(),
+ description: description.clone(),
},
)),
}))
@@ -243,11 +254,19 @@ impl HashExpr {
Some(protobuf::physical_expr_node::ExprType::HashExpr(h)) => h,
_ => return internal_err!("PhysicalExprNode is not a HashExpr"),
};
- let on_columns = ctx.decode_children_expressions(&hash_expr.on_columns)?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::PhysicalHashExprNode {
+ on_columns,
+ seed0,
+ description,
+ } = hash_expr;
+
+ let on_columns = ctx.decode_children_expressions(on_columns)?;
Ok(Arc::new(HashExpr::new(
on_columns,
- SeededRandomState::with_seed(hash_expr.seed0),
- hash_expr.description.clone(),
+ SeededRandomState::with_seed(*seed0),
+ description.clone(),
)))
}
}
@@ -394,6 +413,18 @@ impl PhysicalExpr for HashTableLookupExpr {
use datafusion_proto_models::protobuf;
use datafusion_proto_models::protobuf::physical_expr_node::ExprType;
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here, forcing a decision about whether the lit(true)
+ // replacement below is still the right thing to emit.
+ let Self {
+ // deliberately not serialized: the whole expression is replaced
+ // with lit(true), see the comment below
+ on_columns: _,
+ random_state: _,
+ map: _,
+ description: _,
+ } = self;
+
// HashTableLookupExpr holds a runtime Arc<Map> (the build-side hash
// table) that cannot be serialized, so it is replaced with lit(true).
//
diff --git a/datafusion/physical-plan/src/joins/nested_loop_join.rs b/datafusion/physical-plan/src/joins/nested_loop_join.rs
index 0de1dfdaa2..7fc1ba45c6 100644
--- a/datafusion/physical-plan/src/joins/nested_loop_join.rs
+++ b/datafusion/physical-plan/src/joins/nested_loop_join.rs
@@ -805,13 +805,35 @@ impl ExecutionPlan for NestedLoopJoinExec {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
use datafusion_proto_models::protobuf;
- let left = ctx.encode_child(self.left())?;
- let right = ctx.encode_child(self.right())?;
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ left,
+ right,
+ filter,
+ join_type,
+ projection,
+ // derived from the children's schemas by `try_new` on decode
+ join_schema: _,
+ // runtime build-side state, not part of the plan
+ build_side_data: _,
+ // runtime spill state, not part of the plan
+ left_spill_data: _,
+ // recomputed by `try_new` on decode
+ column_indices: _,
+ // runtime metrics, not part of the plan
+ metrics: _,
+ // recomputed by `try_new` on decode
+ cache: _,
+ } = self;
+
+ let left = ctx.encode_child(left)?;
+ let right = ctx.encode_child(right)?;
- let join_type = crate::joins::proto::join_type_to_proto(*self.join_type());
+ let join_type = crate::joins::proto::join_type_to_proto(*join_type);
- let filter = self
- .filter()
+ let filter = filter
+ .as_ref()
.map(|f| crate::joins::proto::join_filter_to_proto(f, ctx))
.transpose()?;
@@ -823,7 +845,7 @@ impl ExecutionPlan for NestedLoopJoinExec {
right: Some(Box::new(right)),
join_type: join_type.into(),
filter,
- projection: match self.projection.as_ref() {
+ projection: match projection.as_ref() {
None => Vec::new(),
Some(v) if v.is_empty() => vec![u32::MAX],
Some(v) => v.iter().map(|x| *x as u32).collect(),
@@ -849,31 +871,32 @@ impl NestedLoopJoinExec {
"NestedLoopJoinExec",
);
- let left = ctx.decode_required_child(
- join.left.as_deref(),
- "NestedLoopJoinExec",
- "left",
- )?;
- let right = ctx.decode_required_child(
- join.right.as_deref(),
- "NestedLoopJoinExec",
- "right",
- )?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::NestedLoopJoinExecNode {
+ left,
+ right,
+ join_type,
+ filter,
+ projection,
+ } = &**join;
- let join_type = crate::joins::proto::join_type_from_proto(
- join.join_type,
- "NestedLoopJoinExec",
- )?;
+ let left =
+ ctx.decode_required_child(left.as_deref(), "NestedLoopJoinExec", "left")?;
+ let right =
+ ctx.decode_required_child(right.as_deref(), "NestedLoopJoinExec", "right")?;
+
+ let join_type =
+ crate::joins::proto::join_type_from_proto(*join_type, "NestedLoopJoinExec")?;
- let filter = join
- .filter
+ let filter = filter
.as_ref()
.map(|f| {
crate::joins::proto::join_filter_from_proto(f, ctx, "NestedLoopJoinExec")
})
.transpose()?;
- let projection = match join.projection.as_slice() {
+ let projection = match projection.as_slice() {
[] => None,
[u32::MAX] => Some(Vec::new()),
indices => Some(indices.iter().map(|i| *i as usize).collect()),
diff --git a/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs b/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs
index b48905500d..dc8540fe6d 100644
--- a/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs
+++ b/datafusion/physical-plan/src/joins/sort_merge_join/exec.rs
@@ -686,10 +686,31 @@ impl ExecutionPlan for SortMergeJoinExec {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
use datafusion_proto_models::protobuf;
- let left = ctx.encode_child(self.left())?;
- let right = ctx.encode_child(self.right())?;
- let on = self
- .on()
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ left,
+ right,
+ on,
+ filter,
+ join_type,
+ sort_options,
+ null_equality,
+ // derived from the children's schemas by `try_new` on decode
+ schema: _,
+ // runtime metrics, not part of the plan
+ metrics: _,
+ // recomputed from `on` and `sort_options` by `try_new` on decode
+ left_sort_exprs: _,
+ // recomputed from `on` and `sort_options` by `try_new` on decode
+ right_sort_exprs: _,
+ // recomputed by `try_new` on decode
+ cache: _,
+ } = self;
+
+ let left = ctx.encode_child(left)?;
+ let right = ctx.encode_child(right)?;
+ let on = on
.iter()
.map(|(left, right)| {
Ok(protobuf::JoinOn {
@@ -699,16 +720,13 @@ impl ExecutionPlan for SortMergeJoinExec {
})
.collect::<Result<Vec<_>>>()?;
- let join_type = crate::joins::proto::join_type_to_proto(self.join_type());
- let null_equality =
- crate::joins::proto::null_equality_to_proto(self.null_equality());
- let filter = self
- .filter()
+ let join_type = crate::joins::proto::join_type_to_proto(*join_type);
+ let null_equality = crate::joins::proto::null_equality_to_proto(*null_equality);
+ let filter = filter
.as_ref()
.map(|filter| crate::joins::proto::join_filter_to_proto(filter, ctx))
.transpose()?;
- let sort_options = self
- .sort_options()
+ let sort_options = sort_options
.iter()
.map(|options| protobuf::SortExprNode {
expr: None,
@@ -753,20 +771,25 @@ impl SortMergeJoinExec {
protobuf::physical_plan_node::PhysicalPlanType::SortMergeJoin,
"SortMergeJoinExec",
);
- let left = ctx.decode_required_child(
- sort_join.left.as_deref(),
- "SortMergeJoinExec",
- "left",
- )?;
- let right = ctx.decode_required_child(
- sort_join.right.as_deref(),
- "SortMergeJoinExec",
- "right",
- )?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::SortMergeJoinExecNode {
+ left,
+ right,
+ on,
+ join_type,
+ filter,
+ sort_options,
+ null_equality,
+ } = &**sort_join;
+
+ let left =
+ ctx.decode_required_child(left.as_deref(), "SortMergeJoinExec", "left")?;
+ let right =
+ ctx.decode_required_child(right.as_deref(), "SortMergeJoinExec", "right")?;
let left_schema = left.schema();
let right_schema = right.schema();
- let on = sort_join
- .on
+ let on = on
.iter()
.map(|columns| {
let left = ctx.decode_required_expr(
@@ -785,16 +808,13 @@ impl SortMergeJoinExec {
})
.collect::<Result<JoinOn>>()?;
- let join_type = crate::joins::proto::join_type_from_proto(
- sort_join.join_type,
- "SortMergeJoinExec",
- )?;
+ let join_type =
+ crate::joins::proto::join_type_from_proto(*join_type, "SortMergeJoinExec")?;
let null_equality = crate::joins::proto::null_equality_from_proto(
- sort_join.null_equality,
+ *null_equality,
"SortMergeJoinExec",
)?;
- let filter = sort_join
- .filter
+ let filter = filter
.as_ref()
.map(|filter| {
crate::joins::proto::join_filter_from_proto(
@@ -804,8 +824,7 @@ impl SortMergeJoinExec {
)
})
.transpose()?;
- let sort_options = sort_join
- .sort_options
+ let sort_options = sort_options
.iter()
.map(|options| SortOptions {
descending: !options.asc,
diff --git a/datafusion/physical-plan/src/joins/symmetric_hash_join.rs b/datafusion/physical-plan/src/joins/symmetric_hash_join.rs
index 0c6e84b36c..e6dad48e25 100644
--- a/datafusion/physical-plan/src/joins/symmetric_hash_join.rs
+++ b/datafusion/physical-plan/src/joins/symmetric_hash_join.rs
@@ -666,10 +666,32 @@ impl ExecutionPlan for SymmetricHashJoinExec {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalPlanNode>> {
use datafusion_proto_models::protobuf;
- let left = ctx.encode_child(self.left())?;
- let right = ctx.encode_child(self.right())?;
- let on = self
- .on()
+ // Destructure exhaustively (no `..`) so that a newly added field is a
+ // compile error here instead of being silently left out of the proto.
+ let Self {
+ left,
+ right,
+ on,
+ filter,
+ join_type,
+ null_equality,
+ left_sort_exprs,
+ right_sort_exprs,
+ mode,
+ // deterministic (`RandomState::with_seed(0)`), rebuilt identically
+ // by `try_new` on decode
+ random_state: _,
+ // runtime metrics, not part of the plan
+ metrics: _,
+ // recomputed by `try_new` on decode
+ column_indices: _,
+ // recomputed by `try_new` on decode
+ cache: _,
+ } = self;
+
+ let left = ctx.encode_child(left)?;
+ let right = ctx.encode_child(right)?;
+ let on = on
.iter()
.map(|(left, right)| {
Ok(protobuf::JoinOn {
@@ -679,7 +701,7 @@ impl ExecutionPlan for SymmetricHashJoinExec {
})
.collect::<Result<Vec<_>>>()?;
- let join_type = match self.join_type() {
+ let join_type = match join_type {
JoinType::Inner => protobuf::JoinType::Inner,
JoinType::Left => protobuf::JoinType::Left,
JoinType::Right => protobuf::JoinType::Right,
@@ -691,11 +713,11 @@ impl ExecutionPlan for SymmetricHashJoinExec {
JoinType::LeftMark => protobuf::JoinType::Leftmark,
JoinType::RightMark => protobuf::JoinType::Rightmark,
};
- let null_equality = match self.null_equality() {
+ let null_equality = match null_equality {
NullEquality::NullEqualsNothing => protobuf::NullEquality::NullEqualsNothing,
NullEquality::NullEqualsNull => protobuf::NullEquality::NullEqualsNull,
};
- let partition_mode = match self.partition_mode() {
+ let partition_mode = match mode {
StreamJoinPartitionMode::SinglePartition => {
protobuf::StreamPartitionMode::SinglePartition
}
@@ -703,8 +725,8 @@ impl ExecutionPlan for SymmetricHashJoinExec {
protobuf::StreamPartitionMode::PartitionedExec
}
};
- let filter = self
- .filter()
+ let filter = filter
+ .as_ref()
.map(|filter| -> Result<protobuf::JoinFilter> {
let expression = ctx.encode_expr(filter.expression())?;
let column_indices = filter
@@ -732,12 +754,12 @@ impl ExecutionPlan for SymmetricHashJoinExec {
let expr_ctx = ctx.expr_ctx();
let left_sort_exprs =
datafusion_physical_expr_common::sort_expr::optional_ordering_try_to_proto(
- self.left_sort_exprs(),
+ left_sort_exprs.as_ref(),
&expr_ctx,
)?;
let right_sort_exprs =
datafusion_physical_expr_common::sort_expr::optional_ordering_try_to_proto(
- self.right_sort_exprs(),
+ right_sort_exprs.as_ref(),
&expr_ctx,
)?;
@@ -780,20 +802,30 @@ impl SymmetricHashJoinExec {
protobuf::physical_plan_node::PhysicalPlanType::SymmetricHashJoin,
"SymmetricHashJoinExec",
);
- let left = ctx.decode_required_child(
- sym_join.left.as_deref(),
- "SymmetricHashJoinExec",
- "left",
- )?;
+ // Destructure exhaustively (no `..`) so that a newly added proto field
+ // is a compile error here instead of being silently ignored.
+ let protobuf::SymmetricHashJoinExecNode {
+ left,
+ right,
+ on,
+ join_type,
+ partition_mode,
+ null_equality,
+ filter,
+ left_sort_exprs,
+ right_sort_exprs,
+ } = &**sym_join;
+
+ let left =
+ ctx.decode_required_child(left.as_deref(), "SymmetricHashJoinExec", "left")?;
let right = ctx.decode_required_child(
- sym_join.right.as_deref(),
+ right.as_deref(),
"SymmetricHashJoinExec",
"right",
)?;
let left_schema = left.schema();
let right_schema = right.schema();
- let on = sym_join
- .on
+ let on = on
.iter()
.map(|columns| {
let left = ctx.decode_required_expr(
@@ -812,51 +844,47 @@ impl SymmetricHashJoinExec {
})
.collect::<Result<JoinOn>>()?;
- let join_type =
- match protobuf::JoinType::try_from(sym_join.join_type).map_err(|_| {
- internal_datafusion_err!(
- "SymmetricHashJoinExec: unknown JoinType {}",
- sym_join.join_type
- )
- })? {
- protobuf::JoinType::Inner => JoinType::Inner,
- protobuf::JoinType::Left => JoinType::Left,
- protobuf::JoinType::Right => JoinType::Right,
- protobuf::JoinType::Full => JoinType::Full,
- protobuf::JoinType::Leftsemi => JoinType::LeftSemi,
- protobuf::JoinType::Rightsemi => JoinType::RightSemi,
- protobuf::JoinType::Leftanti => JoinType::LeftAnti,
- protobuf::JoinType::Rightanti => JoinType::RightAnti,
- protobuf::JoinType::Leftmark => JoinType::LeftMark,
- protobuf::JoinType::Rightmark => JoinType::RightMark,
- };
- let null_equality = match protobuf::NullEquality::try_from(sym_join.null_equality)
+ let join_type = match protobuf::JoinType::try_from(*join_type).map_err(|_| {
+ internal_datafusion_err!(
+ "SymmetricHashJoinExec: unknown JoinType {join_type}"
+ )
+ })? {
+ protobuf::JoinType::Inner => JoinType::Inner,
+ protobuf::JoinType::Left => JoinType::Left,
+ protobuf::JoinType::Right => JoinType::Right,
+ protobuf::JoinType::Full => JoinType::Full,
+ protobuf::JoinType::Leftsemi => JoinType::LeftSemi,
+ protobuf::JoinType::Rightsemi => JoinType::RightSemi,
+ protobuf::JoinType::Leftanti => JoinType::LeftAnti,
+ protobuf::JoinType::Rightanti => JoinType::RightAnti,
+ protobuf::JoinType::Leftmark => JoinType::LeftMark,
+ protobuf::JoinType::Rightmark => JoinType::RightMark,
+ };
+ let null_equality = match protobuf::NullEquality::try_from(*null_equality)
.map_err(|_| {
internal_datafusion_err!(
- "SymmetricHashJoinExec: unknown NullEquality {}",
- sym_join.null_equality
+ "SymmetricHashJoinExec: unknown NullEquality {null_equality}"
)
})? {
protobuf::NullEquality::NullEqualsNothing => NullEquality::NullEqualsNothing,
protobuf::NullEquality::NullEqualsNull => NullEquality::NullEqualsNull,
};
- let partition_mode =
- match protobuf::StreamPartitionMode::try_from(sym_join.partition_mode)
- .map_err(|_| {
- internal_datafusion_err!(
- "SymmetricHashJoinExec: unknown StreamPartitionMode {}",
- sym_join.partition_mode
- )
- })? {
- protobuf::StreamPartitionMode::SinglePartition => {
- StreamJoinPartitionMode::SinglePartition
- }
- protobuf::StreamPartitionMode::PartitionedExec => {
- StreamJoinPartitionMode::Partitioned
- }
- };
- let filter = sym_join
- .filter
+ let partition_mode = match protobuf::StreamPartitionMode::try_from(
+ *partition_mode,
+ )
+ .map_err(|_| {
+ internal_datafusion_err!(
+ "SymmetricHashJoinExec: unknown StreamPartitionMode {partition_mode}"
+ )
+ })? {
+ protobuf::StreamPartitionMode::SinglePartition => {
+ StreamJoinPartitionMode::SinglePartition
+ }
+ protobuf::StreamPartitionMode::PartitionedExec => {
+ StreamJoinPartitionMode::Partitioned
+ }
+ };
+ let filter = filter
.as_ref()
.map(|filter| -> Result<JoinFilter> {
let schema: Schema = filter
@@ -905,12 +933,12 @@ impl SymmetricHashJoinExec {
.transpose()?;
let left_sort_exprs =
datafusion_physical_expr_common::sort_expr::optional_ordering_try_from_proto(
- &sym_join.left_sort_exprs,
+ left_sort_exprs,
&ctx.expr_ctx(left_schema.as_ref()),
)?;
let right_sort_exprs =
datafusion_physical_expr_common::sort_expr::optional_ordering_try_from_proto(
- &sym_join.right_sort_exprs,
+ right_sort_exprs,
&ctx.expr_ctx(right_schema.as_ref()),
)?;