jayshrivastava commented on code in PR #22464:
URL: https://github.com/apache/datafusion/pull/22464#discussion_r3298627733


##########
datafusion/physical-expr/src/expressions/unknown_column.rs:
##########
@@ -99,3 +139,83 @@ impl PartialEq for UnKnownColumn {
         false
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[cfg(feature = "proto")]
+    use std::sync::Arc;
+
+    #[cfg(feature = "proto")]
+    use arrow::datatypes::Schema;
+
+    #[cfg(feature = "proto")]
+    use datafusion_common::{Result, internal_err};
+
+    #[cfg(feature = "proto")]
+    use 
datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecodeCtx;
+
+    #[cfg(feature = "proto")]
+    struct DummyDecode;
+
+    #[cfg(feature = "proto")]
+    impl 
datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecode
+        for DummyDecode
+    {
+        fn decode(
+            &self,
+            _node: &datafusion_proto_models::protobuf::PhysicalExprNode,
+            _schema: &Schema,
+        ) -> Result<Arc<dyn PhysicalExpr>> {
+            internal_err!("decode should not be called")
+        }
+    }
+
+    #[cfg(feature = "proto")]
+    #[test]
+    fn try_from_proto_reports_found_variant() {
+        use datafusion_proto_models::protobuf;
+
+        let node = protobuf::PhysicalExprNode {
+            expr_id: Some(7),
+            expr_type: Some(protobuf::physical_expr_node::ExprType::Column(
+                protobuf::PhysicalColumn {
+                    name: "col_a".to_string(),
+                    index: 0,
+                },
+            )),
+        };
+        let schema = Schema::empty();
+        let decoder = DummyDecode;
+        let ctx = PhysicalExprDecodeCtx::new(&schema, &decoder);
+
+        let err = UnKnownColumn::try_from_proto(&node, &ctx).unwrap_err();
+        let err = err.to_string();
+
+        assert!(err.contains("expr_id=Some(7)"));
+        assert!(err.contains("PhysicalColumn"));
+    }
+
+    #[cfg(feature = "proto")]
+    #[test]
+    fn unknown_column_proto_roundtrip() {
+        use datafusion_proto_models::protobuf;
+
+        let name = "col_b".to_string();
+        let node = protobuf::PhysicalExprNode {
+            expr_id: Some(42),
+            expr_type: 
Some(protobuf::physical_expr_node::ExprType::UnknownColumn(
+                protobuf::UnknownColumn { name: name.clone() },
+            )),
+        };
+
+        let schema = Schema::empty();
+        let decoder = DummyDecode;
+        let ctx = PhysicalExprDecodeCtx::new(&schema, &decoder);
+
+        let decoded = UnKnownColumn::try_from_proto(&node, &ctx).unwrap();
+        let col = decoded.as_ref().downcast_ref::<UnKnownColumn>().unwrap();
+        assert_eq!(col.name(), name.as_str());

Review Comment:
   I think what Kumar means by roundtrip is something like 
   
   ```rust
       use crate::proto_test_util::{
           StubDecoder, StubEncoder
       };
   
       #[test]
       fn unknown_column_proto_roundtrip() {
           let expr = UnKnownColumn::new("col_a");
           let encoder = StubEncoder::ok();
           let ctx = PhysicalExprEncodeCtx::new(&encoder);
           let encoded = expr.try_to_proto(&ctx).unwrap().unwrap();
   
           let decode_ctx = PhysicalExprDecodeCtx::new(&Schema::empty(), 
&UnreachableDecoder {});
           let decoded = UnKnownColumn::try_from_proto(&encoded, 
&decode_ctx).unwrap();
           let roundtripped_expr = 
decoded.as_ref().downcast_ref::<UnKnownColumn>().unwrap();
           assert_eq!(&expr, roundtripped_expr);
       }
   ```
   
   I approved the PR bc I figured there would already be a roundtrip test in 
`datafusion/datafusion/proto/tests/cases/roundtrip_physical_plan.rs` but that 
doesn't seem to be the case.
   
   I agree with Kumar that we should add some here.



-- 
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]

Reply via email to