From b5082e01bfa95ecb6a8960b1c9594c951c0b8b6a Mon Sep 17 00:00:00 2001 From: Kun Liu Date: Mon, 20 Dec 2021 15:18:33 +0800 Subject: [PATCH] minor support mod operation for expr (#1467) --- ballista/rust/core/src/serde/mod.rs | 1 + datafusion/src/logical_plan/operators.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/ballista/rust/core/src/serde/mod.rs b/ballista/rust/core/src/serde/mod.rs index b5c3c3c36468..f5442c40e660 100644 --- a/ballista/rust/core/src/serde/mod.rs +++ b/ballista/rust/core/src/serde/mod.rs @@ -97,6 +97,7 @@ pub(crate) fn from_proto_binary_op(op: &str) -> Result "Minus" => Ok(Operator::Minus), "Multiply" => Ok(Operator::Multiply), "Divide" => Ok(Operator::Divide), + "Modulo" => Ok(Operator::Modulo), "Like" => Ok(Operator::Like), "NotLike" => Ok(Operator::NotLike), other => Err(proto_error(format!( diff --git a/datafusion/src/logical_plan/operators.rs b/datafusion/src/logical_plan/operators.rs index 50bd682ae3f0..634439940307 100644 --- a/datafusion/src/logical_plan/operators.rs +++ b/datafusion/src/logical_plan/operators.rs @@ -127,6 +127,14 @@ impl ops::Div for Expr { } } +impl ops::Rem for Expr { + type Output = Self; + + fn rem(self, rhs: Self) -> Self { + binary_expr(self, Operator::Modulo, rhs) + } +} + #[cfg(test)] mod tests { use crate::prelude::lit; @@ -149,5 +157,9 @@ mod tests { format!("{:?}", lit(1u32) / lit(2u32)), "UInt32(1) / UInt32(2)" ); + assert_eq!( + format!("{:?}", lit(1u32) % lit(2u32)), + "UInt32(1) % UInt32(2)" + ); } }