Apache DataFusion SQL Query Engine
implement protobuf serde for all binary operators (#3441)
Andy Grovedeea8c3e8436
diff --git a/datafusion/proto/src/from_proto.rs b/datafusion/proto/src/from_proto.rsindex e0db97c0ca..c93d3a8775 100644--- a/datafusion/proto/src/from_proto.rs+++ b/datafusion/proto/src/from_proto.rs@@ -1529,6 +1529,17 @@ fn from_proto_binary_op(op: &str) -> Result<Operator, Error> {"Modulo" => Ok(Operator::Modulo),"Like" => Ok(Operator::Like),"NotLike" => Ok(Operator::NotLike),+ "IsDistinctFrom" => Ok(Operator::IsDistinctFrom),+ "IsNotDistinctFrom" => Ok(Operator::IsNotDistinctFrom),+ "BitwiseAnd" => Ok(Operator::BitwiseAnd),+ "BitwiseOr" => Ok(Operator::BitwiseOr),+ "BitwiseShiftLeft" => Ok(Operator::BitwiseShiftLeft),+ "BitwiseShiftRight" => Ok(Operator::BitwiseShiftRight),+ "RegexIMatch" => Ok(Operator::RegexIMatch),+ "RegexMatch" => Ok(Operator::RegexMatch),+ "RegexNotIMatch" => Ok(Operator::RegexNotIMatch),+ "RegexNotMatch" => Ok(Operator::RegexNotMatch),+ "StringConcat" => Ok(Operator::StringConcat),other => Err(proto_error(format!("Unsupported binary operator '{:?}'",otherdiff --git a/datafusion/proto/src/lib.rs b/datafusion/proto/src/lib.rsindex 06c86705de..f0da137936 100644--- a/datafusion/proto/src/lib.rs+++ b/datafusion/proto/src/lib.rs@@ -66,7 +66,7 @@ mod roundtrip_tests {use datafusion_expr::logical_plan::{Extension, UserDefinedLogicalNode};use datafusion_expr::{col, lit, Accumulator, AggregateFunction, AggregateState,- BuiltinScalarFunction::Sqrt, Expr, LogicalPlan, Volatility,+ BuiltinScalarFunction::Sqrt, Expr, LogicalPlan, Operator, Volatility,};use prost::Message;use std::any::Any;@@ -836,6 +836,40 @@ mod roundtrip_tests {roundtrip_expr_test(test_expr, ctx);}+ #[test]+ fn roundtrip_binary_op() {+ fn test(op: Operator) {+ let test_expr = Expr::BinaryExpr {+ left: Box::new(lit(1.0_f32)),+ op,+ right: Box::new(lit(2.0_f32)),+ };+ let ctx = SessionContext::new();+ roundtrip_expr_test(test_expr, ctx);+ }+ test(Operator::StringConcat);+ test(Operator::RegexNotIMatch);+ test(Operator::RegexNotMatch);+ test(Operator::RegexIMatch);+ test(Operator::RegexMatch);+ test(Operator::Like);+ test(Operator::NotLike);+ test(Operator::BitwiseShiftRight);+ test(Operator::BitwiseShiftLeft);+ test(Operator::BitwiseAnd);+ test(Operator::BitwiseOr);+ test(Operator::IsDistinctFrom);+ test(Operator::IsNotDistinctFrom);+ test(Operator::And);+ test(Operator::Or);+ test(Operator::Eq);+ test(Operator::NotEq);+ test(Operator::Lt);+ test(Operator::LtEq);+ test(Operator::Gt);+ test(Operator::GtEq);+ }+#[test]fn roundtrip_case() {let test_expr = Expr::Case {