avantgardnerio commented on code in PR #2892:
URL: https://github.com/apache/arrow-datafusion/pull/2892#discussion_r920412642
##########
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:
Running that raw JSON through [this
formatter](https://github.com/lydell/json-stringify-pretty-compact) produces
some encouraging output:
```
{
"projection": {
"input": {
"sort": {
"input": {
"projection": {
"input": {
"listingScan": {
"tableName": "alltypes_plain",
"paths":
["file:///home/bgardner/workspace/arrow-datafusion/parquet-testing/data/alltypes_plain.parquet"],
"fileExtension": ".parquet",
"schema": {
"columns": [
{"name": "id", "arrowType": {"INT32": {}}, "nullable":
true},
{"name": "bool_col", "arrowType": {"BOOL": {}},
"nullable": true},
{"name": "tinyint_col", "arrowType": {"INT32": {}},
"nullable": true},
{"name": "smallint_col", "arrowType": {"INT32": {}},
"nullable": true},
{"name": "int_col", "arrowType": {"INT32": {}},
"nullable": true},
{"name": "bigint_col", "arrowType": {"INT64": {}},
"nullable": true},
{"name": "float_col", "arrowType": {"FLOAT32": {}},
"nullable": true},
{"name": "double_col", "arrowType": {"FLOAT64": {}},
"nullable": true},
{"name": "date_string_col", "arrowType": {"BINARY": {}},
"nullable": true},
{"name": "string_col", "arrowType": {"BINARY": {}},
"nullable": true},
{"name": "timestamp_col", "arrowType": {"TIMESTAMP":
{"timeUnit": "Nanosecond"}}, "nullable": true}
]
},
"collectStat": true,
"targetPartitions": 16,
"parquet": {"enablePruning": true}
}
},
"expr": [
{"column": {"name": "id", "relation": {"relation":
"alltypes_plain"}}},
{"column": {"name": "int_col", "relation": {"relation":
"alltypes_plain"}}},
{"column": {"name": "double_col", "relation": {"relation":
"alltypes_plain"}}}
]
}
},
"expr": [
{"sort": {"expr": {"column": {"name": "int_col", "relation":
{"relation": "alltypes_plain"}}}, "asc": true}},
{"sort": {"expr": {"column": {"name": "double_col", "relation":
{"relation": "alltypes_plain"}}}, "asc": true}}
]
}
},
"expr": [{"column": {"name": "id", "relation": {"relation":
"alltypes_plain"}}}]
}
}
```
--
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]