Skip to content

Commit c5c78b2

Browse files
Anurag Tryambak RautAnurag Tryambak Raut
authored andcommitted
refactor: add try_to_proto to HashTableLookupExpr
Part of #22435. Adds try_to_proto to HashTableLookupExpr so it participates in the expression-local serialization pattern introduced in #21929. HashTableLookupExpr holds a runtime Arc<Map> that cannot be serialized, so try_to_proto replaces it with lit(true). This is safe because the filter is a performance optimisation only — lit(true) passes all rows and the join produces correct results either way. The centralized arm in to_proto.rs remains as a fallback for now.
1 parent 077f08a commit c5c78b2

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ impl HashTableLookupExpr {
242242
}
243243
}
244244

245+
246+
245247
impl std::fmt::Debug for HashTableLookupExpr {
246248
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
247249
let cols = self
@@ -289,6 +291,38 @@ impl PartialEq for HashTableLookupExpr {
289291

290292
impl Eq for HashTableLookupExpr {}
291293

294+
#[cfg(feature = "proto")]
295+
impl HashTableLookupExpr {
296+
/// Serialize this expression to protobuf.
297+
///
298+
/// `HashTableLookupExpr` holds an `Arc<Map>` (a runtime hash table built
299+
/// on the build side) which cannot be serialized. We replace it with
300+
/// `lit(true)`, which is safe because:
301+
///
302+
/// - The filter is a performance optimisation, not a correctness requirement.
303+
/// - `lit(true)` passes all rows so no valid rows are lost.
304+
/// - In distributed execution the remote worker has no access to the
305+
/// build-side hash table anyway.
306+
pub fn try_to_proto(
307+
&self,
308+
_ctx: &datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx<'_>,
309+
) -> datafusion_common::Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>>
310+
{
311+
use datafusion_proto_common::scalar_value::Value;
312+
use datafusion_proto_common::ScalarValue;
313+
use datafusion_proto_models::protobuf;
314+
use datafusion_proto_models::protobuf::physical_expr_node::ExprType;
315+
316+
let value = ScalarValue {
317+
value: Some(Value::BoolValue(true)),
318+
};
319+
Ok(Some(protobuf::PhysicalExprNode {
320+
expr_id: None,
321+
expr_type: Some(ExprType::Literal(value)),
322+
}))
323+
}
324+
}
325+
292326
impl Display for HashTableLookupExpr {
293327
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
294328
write!(f, "{}", self.description)

0 commit comments

Comments
 (0)