kumarUjjawal commented on code in PR #22463:
URL: https://github.com/apache/datafusion/pull/22463#discussion_r3302725199
##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -181,6 +183,47 @@ impl PhysicalExpr for NotExpr {
write!(f, "NOT ")?;
self.arg.fmt_sql(f)
}
+
+ #[cfg(feature = "proto")]
+ fn try_to_proto(
+ &self,
+ ctx:
&datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx<'_>,
+ ) -> Result<Option<datafusion_proto_models::protobuf::PhysicalExprNode>> {
+ use datafusion_proto_models::protobuf;
+
+ Ok(Some(protobuf::PhysicalExprNode {
+ expr_id: None,
+ expr_type:
Some(protobuf::physical_expr_node::ExprType::NotExpr(Box::new(
+ protobuf::PhysicalNot {
+ expr: Some(Box::new(ctx.encode_child(&self.arg)?)),
+ },
+ ))),
+ }))
+ }
+}
+
+#[cfg(feature = "proto")]
+impl NotExpr {
+ /// Reconstruct a [`NotExpr`] from its protobuf representation.
+ pub fn try_from_proto(
+ node: &datafusion_proto_models::protobuf::PhysicalExprNode,
+ ctx:
&datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecodeCtx<'_>,
+ ) -> Result<Arc<dyn PhysicalExpr>> {
+ use datafusion_proto_models::protobuf;
+
+ let protobuf::PhysicalNot { expr } = match &node.expr_type {
Review Comment:
I think `try_from_proto` should use `ctx.decode_required_expression(...)`
here instead of open-coding the missing-child check and then calling
ctx.decode(...). A helper was added recently for this, can you check, I just
pushed main to this branch?
##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -198,6 +241,46 @@ mod tests {
use arrow::{array::BooleanArray, datatypes::*};
use datafusion_physical_expr_common::physical_expr::fmt_sql;
+ #[cfg(feature = "proto")]
+ #[test]
+ fn test_from_proto_missing_child() {
+ use datafusion_common::DataFusionError;
+ use datafusion_physical_expr_common::physical_expr::proto_decode::{
+ PhysicalExprDecode, PhysicalExprDecodeCtx,
+ };
+ use datafusion_proto_models::protobuf::{
+ PhysicalExprNode, PhysicalNot, physical_expr_node,
+ };
+
+ struct NoopDecoder;
+
+ impl PhysicalExprDecode for NoopDecoder {
+ fn decode(
+ &self,
+ _node: &PhysicalExprNode,
+ _schema: &Schema,
+ ) -> Result<Arc<dyn PhysicalExpr>> {
+ unreachable!("missing child should be rejected before
decoding")
+ }
+ }
+
+ let node = PhysicalExprNode {
+ expr_id: Some(42),
+ expr_type: Some(physical_expr_node::ExprType::NotExpr(Box::new(
+ PhysicalNot { expr: None },
+ ))),
+ };
+ let schema = Schema::empty();
+ let decoder = NoopDecoder;
+ let ctx = PhysicalExprDecodeCtx::new(&schema, &decoder);
+
+ let err = NotExpr::try_from_proto(&node, &ctx).unwrap_err();
+ assert!(matches!(err, DataFusionError::Internal(msg)
+ if msg.contains("NotExpr is missing required field 'expr'")
Review Comment:
I would includes expr_id and the actual expr_type here, let me know what you
think?
##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -198,6 +241,46 @@ mod tests {
use arrow::{array::BooleanArray, datatypes::*};
use datafusion_physical_expr_common::physical_expr::fmt_sql;
+ #[cfg(feature = "proto")]
Review Comment:
I would also move these into a separate #[cfg(all(test, feature = "proto"))]
mod proto_tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]