From af50ffa6546d4e3137ca74ea88ad725a4ff79cf9 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Sat, 10 Sep 2022 16:28:08 -0600 Subject: [PATCH] implement protobuf serde for all binary operators --- datafusion/proto/src/from_proto.rs | 11 +++++++++ datafusion/proto/src/lib.rs | 36 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/datafusion/proto/src/from_proto.rs b/datafusion/proto/src/from_proto.rs index e0db97c0ca8e..c93d3a877579 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 { "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 '{:?}'", other diff --git a/datafusion/proto/src/lib.rs b/datafusion/proto/src/lib.rs index 7e009a846e69..25694616b892 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 {