Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions datafusion/physical-expr/src/expressions/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,16 +1419,26 @@ impl PhysicalExpr for CaseExpr {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>> {
use datafusion_proto_models::protobuf;

let Self {
body,
// Derived from `body` by `try_new` on decode.
eval_method: _,
} = self;
let CaseBody {
expr,
when_then_expr,
else_expr,
} = body;

Ok(Some(protobuf::PhysicalExprNode {
expr_id: None,
expr_type: Some(protobuf::physical_expr_node::ExprType::Case(Box::new(
protobuf::PhysicalCaseNode {
expr: self
.expr()
expr: expr
.as_ref()
.map(|expr| ctx.encode_child(expr).map(Box::new))
.transpose()?,
when_then_expr: self
.when_then_expr()
when_then_expr: when_then_expr
.iter()
.map(|(when_expr, then_expr)| {
Ok(protobuf::PhysicalWhenThen {
Expand All @@ -1437,8 +1447,8 @@ impl PhysicalExpr for CaseExpr {
})
})
.collect::<Result<Vec<_>>>()?,
else_expr: self
.else_expr()
else_expr: else_expr
.as_ref()
.map(|expr| ctx.encode_child(expr).map(Box::new))
.transpose()?,
},
Expand All @@ -1462,30 +1472,36 @@ impl CaseExpr {
protobuf::physical_expr_node::ExprType::Case,
"CaseExpr",
);
let protobuf::PhysicalCaseNode {
expr,
when_then_expr,
else_expr,
} = &**case;

Ok(Arc::new(CaseExpr::try_new(
case.expr
.as_deref()
.map(|expr| ctx.decode(expr))
.transpose()?,
case.when_then_expr
expr.as_deref().map(|expr| ctx.decode(expr)).transpose()?,
when_then_expr
.iter()
.map(|when_then| {
let protobuf::PhysicalWhenThen {
when_expr,
then_expr,
} = when_then;
Ok((
ctx.decode_required_expression(
when_then.when_expr.as_ref(),
when_expr.as_ref(),
"CaseExpr",
"when_expr",
)?,
ctx.decode_required_expression(
when_then.then_expr.as_ref(),
then_expr.as_ref(),
"CaseExpr",
"then_expr",
)?,
))
})
.collect::<Result<Vec<_>>>()?,
case.else_expr
else_expr
.as_deref()
.map(|expr| ctx.decode(expr))
.transpose()?,
Expand Down
25 changes: 19 additions & 6 deletions datafusion/physical-expr/src/expressions/in_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,20 @@ impl InListExpr {
protobuf::physical_expr_node::ExprType::InList,
"InList",
);
let protobuf::PhysicalInListNode {
expr,
list,
negated,
} = &**node;

let expr =
ctx.decode_required_expression(node.expr.as_deref(), "InListExpr", "expr")?;
let list = ctx.decode_children_expressions(&node.list)?;
ctx.decode_required_expression(expr.as_deref(), "InListExpr", "expr")?;
let list = ctx.decode_children_expressions(list)?;

Ok(Arc::new(InListExpr::try_new(
expr,
list,
node.negated,
*negated,
ctx.schema(),
)?))
}
Expand Down Expand Up @@ -479,13 +484,21 @@ impl PhysicalExpr for InListExpr {
) -> Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>> {
use datafusion_proto_models::protobuf;

let Self {
expr,
list,
negated,
// Lookup set rebuilt from `list` by `try_new` on decode.
static_filter: _,
} = self;

Ok(Some(protobuf::PhysicalExprNode {
expr_id: None,
expr_type: Some(protobuf::physical_expr_node::ExprType::InList(Box::new(
protobuf::PhysicalInListNode {
expr: Some(Box::new(ctx.encode_child(&self.expr)?)),
list: ctx.encode_children_expressions(&self.list)?,
negated: self.negated,
expr: Some(Box::new(ctx.encode_child(expr)?)),
list: ctx.encode_children_expressions(list)?,
negated: *negated,
},
))),
}))
Expand Down