avantgardnerio commented on code in PR #2892:
URL: https://github.com/apache/arrow-datafusion/pull/2892#discussion_r920390154


##########
datafusion/proto/src/lib.rs:
##########
@@ -75,19 +78,32 @@ mod roundtrip_tests {
     use std::fmt::Formatter;
     use std::sync::Arc;
 
+    #[cfg(feature = "serde")]
+    fn roundtrip_serde_test(proto: &protobuf::LogicalExprNode) {
+        let string = serde_json::to_string(proto).unwrap();
+        let back: protobuf::LogicalExprNode = 
serde_json::from_str(&string).unwrap();
+        assert_eq!(proto, &back);
+    }
+
+    #[cfg(not(feature = "serde"))]
+    fn roundtrip_serde_test(_proto: &protobuf::LogicalExprNode) {}
+
     // Given a DataFusion logical Expr, convert it to protobuf and back, using 
debug formatting to test
     // equality.
-    macro_rules! roundtrip_expr_test {
-        ($initial_struct:ident, $ctx:ident) => {
-            let proto: protobuf::LogicalExprNode = 
(&$initial_struct).try_into().unwrap();
+    fn roundtrip_expr_test<T, E>(initial_struct: T, ctx: SessionContext)
+    where
+        for<'a> &'a T: TryInto<protobuf::LogicalExprNode, Error = E> + Debug,
+        E: Debug,
+    {
+        let proto: protobuf::LogicalExprNode = 
(&initial_struct).try_into().unwrap();
+        let round_trip: Expr = parse_expr(&proto, &ctx).unwrap();

Review Comment:
   Okay, I got all that sorted, and was able to do what I was trying to use 
this PR for: https://github.com/tustvold/arrow-datafusion/pull/63
   
   I was hoping (naively) to see something like:
   
   ```
   {Projection: { field: "#employee_csv.id",
     Filter: {expr: {left: "#employee_csv.state", op: "IN", right: {
       Subquery: {
         TableScan: {name: "employee_csv", projection=["state"]},
       TableScan: {name: "employee_csv" projection=["id", "state"]
   }}
   ```
   
   Unfortunately (though serializable and deserializable) the result is not as 
human readable as I hoped, and probably not something I'd want to check into a 
test assertion: 
https://gist.github.com/avantgardnerio/35a04950ca768fdfe6579aea08126b74



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

Reply via email to