Skip to content

Commit f8f274f

Browse files
committed
init porting LikeExpr
1 parent 50013e5 commit f8f274f

3 files changed

Lines changed: 65 additions & 35 deletions

File tree

datafusion/physical-expr/src/expressions/like.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,69 @@ impl PhysicalExpr for LikeExpr {
145145
write!(f, " {} ", self.op_name())?;
146146
self.pattern.fmt_sql(f)
147147
}
148+
149+
#[cfg(feature = "proto")]
150+
fn try_to_proto(
151+
&self,
152+
ctx: &datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx<'_>,
153+
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>> {
154+
use datafusion_proto_models::protobuf;
155+
156+
Ok(Some(protobuf::PhysicalExprNode {
157+
expr_id: None,
158+
expr_type: Some(protobuf::physical_expr_node::ExprType::LikeExpr(Box::new(
159+
protobuf::PhysicalLikeExprNode {
160+
negated: self.negated,
161+
case_insensitive: self.case_insensitive,
162+
expr: Some(Box::new(ctx.encode_child(&self.expr)?)),
163+
pattern: Some(Box::new(ctx.encode_child(&self.pattern)?)),
164+
},
165+
))),
166+
}))
167+
}
168+
}
169+
170+
#[cfg(feature = "proto")]
171+
impl LikeExpr {
172+
/// Reconstruct a [`LikeExpr`] from its protobuf representation.
173+
///
174+
/// Takes the whole [`PhysicalExprNode`] so the decode signature matches
175+
/// other migrated expressions and can inspect outer-node metadata if
176+
/// needed in the future.
177+
///
178+
/// [`PhysicalExprNode`]: datafusion_proto_models::protobuf::PhysicalExprNode
179+
pub fn try_from_proto(
180+
node: &datafusion_proto_models::protobuf::PhysicalExprNode,
181+
ctx: &datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecodeCtx<'_>,
182+
) -> Result<Arc<dyn PhysicalExpr>> {
183+
use datafusion_common::internal_err;
184+
use datafusion_proto_models::protobuf;
185+
186+
let like_expr = match &node.expr_type {
187+
Some(protobuf::physical_expr_node::ExprType::LikeExpr(like_expr)) => {
188+
like_expr.as_ref()
189+
}
190+
_ => return internal_err!("PhysicalExprNode is not a LikeExpr"),
191+
};
192+
193+
let expr = like_expr.expr.as_deref().ok_or_else(|| {
194+
datafusion_common::DataFusionError::Internal(
195+
"LikeExpr is missing required field 'expr'".to_string(),
196+
)
197+
})?;
198+
let pattern = like_expr.pattern.as_deref().ok_or_else(|| {
199+
datafusion_common::DataFusionError::Internal(
200+
"LikeExpr is missing required field 'pattern'".to_string(),
201+
)
202+
})?;
203+
204+
Ok(Arc::new(LikeExpr::new(
205+
like_expr.negated,
206+
like_expr.case_insensitive,
207+
ctx.decode(expr)?,
208+
ctx.decode(pattern)?,
209+
)))
210+
}
148211
}
149212

150213
/// used for optimize Dictionary like

datafusion/proto/src/physical_plan/from_proto.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,7 @@ pub fn parse_physical_expr_with_converter(
426426
.with_nullable(e.nullable),
427427
)
428428
}
429-
ExprType::LikeExpr(like_expr) => Arc::new(LikeExpr::new(
430-
like_expr.negated,
431-
like_expr.case_insensitive,
432-
parse_required_physical_expr(
433-
like_expr.expr.as_deref(),
434-
ctx,
435-
"expr",
436-
input_schema,
437-
proto_converter,
438-
)?,
439-
parse_required_physical_expr(
440-
like_expr.pattern.as_deref(),
441-
ctx,
442-
"pattern",
443-
input_schema,
444-
proto_converter,
445-
)?,
446-
)),
429+
ExprType::LikeExpr(_) => LikeExpr::try_from_proto(proto, &decode_ctx)?,
447430
ExprType::HashExpr(hash_expr) => {
448431
let on_columns = parse_physical_exprs(
449432
&hash_expr.on_columns,

datafusion/proto/src/physical_plan/to_proto.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use datafusion_physical_expr::window::{SlidingAggregateWindowExpr, StandardWindo
3737
use datafusion_physical_expr_common::sort_expr::PhysicalSortExpr;
3838
use datafusion_physical_plan::expressions::{
3939
CaseExpr, CastExpr, DynamicFilterPhysicalExpr, InListExpr, IsNotNullExpr, IsNullExpr,
40-
LikeExpr, Literal, NegativeExpr, NotExpr, TryCastExpr, UnKnownColumn,
40+
Literal, NegativeExpr, NotExpr, TryCastExpr, UnKnownColumn,
4141
};
4242
use datafusion_physical_plan::joins::{HashExpr, HashTableLookupExpr};
4343
use datafusion_physical_plan::udaf::AggregateFunctionExpr;
@@ -486,22 +486,6 @@ pub fn serialize_physical_expr_with_converter(
486486
},
487487
)),
488488
})
489-
} else if let Some(expr) = expr.downcast_ref::<LikeExpr>() {
490-
Ok(protobuf::PhysicalExprNode {
491-
expr_id,
492-
expr_type: Some(protobuf::physical_expr_node::ExprType::LikeExpr(Box::new(
493-
protobuf::PhysicalLikeExprNode {
494-
negated: expr.negated(),
495-
case_insensitive: expr.case_insensitive(),
496-
expr: Some(Box::new(
497-
proto_converter.physical_expr_to_proto(expr.expr(), codec)?,
498-
)),
499-
pattern: Some(Box::new(
500-
proto_converter.physical_expr_to_proto(expr.pattern(), codec)?,
501-
)),
502-
},
503-
))),
504-
})
505489
} else if let Some(expr) = expr.downcast_ref::<HashExpr>() {
506490
Ok(protobuf::PhysicalExprNode {
507491
expr_id,

0 commit comments

Comments
 (0)