Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions datafusion/expr/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ impl fmt::Display for Operator {
}
}

/// Support `<expr> + <expr>` fluent style
impl ops::Add for Expr {
type Output = Self;

Expand All @@ -243,6 +244,7 @@ impl ops::Add for Expr {
}
}

/// Support `<expr> - <expr>` fluent style
impl ops::Sub for Expr {
type Output = Self;

Expand All @@ -251,6 +253,7 @@ impl ops::Sub for Expr {
}
}

/// Support `<expr> * <expr>` fluent style
impl ops::Mul for Expr {
type Output = Self;

Expand All @@ -259,6 +262,7 @@ impl ops::Mul for Expr {
}
}

/// Support `<expr> / <expr>` fluent style
impl ops::Div for Expr {
type Output = Self;

Expand All @@ -267,6 +271,7 @@ impl ops::Div for Expr {
}
}

/// Support `<expr> % <expr>` fluent style
impl ops::Rem for Expr {
type Output = Self;

Expand All @@ -275,6 +280,60 @@ impl ops::Rem for Expr {
}
}

/// Support `<expr> & <expr>` fluent style
impl ops::BitAnd for Expr {
type Output = Self;

fn bitand(self, rhs: Self) -> Self {
binary_expr(self, Operator::BitwiseAnd, rhs)
}
}

/// Support `<expr> | <expr>` fluent style
impl ops::BitOr for Expr {
type Output = Self;

fn bitor(self, rhs: Self) -> Self {
binary_expr(self, Operator::BitwiseOr, rhs)
}
}

/// Support `<expr> ^ <expr>` fluent style
impl ops::BitXor for Expr {
type Output = Self;

fn bitxor(self, rhs: Self) -> Self {
binary_expr(self, Operator::BitwiseXor, rhs)
}
}

/// Support `<expr> << <expr>` fluent style
impl ops::Shl for Expr {
type Output = Self;

fn shl(self, rhs: Self) -> Self::Output {
binary_expr(self, Operator::BitwiseShiftLeft, rhs)
}
}

/// Support `<expr> >> <expr>` fluent style
impl ops::Shr for Expr {
type Output = Self;

fn shr(self, rhs: Self) -> Self::Output {
binary_expr(self, Operator::BitwiseShiftRight, rhs)
}
}

/// Support `- <expr>` fluent style
impl ops::Neg for Expr {
type Output = Self;

fn neg(self) -> Self::Output {
Expr::Negative(Box::new(self))
}
}

#[cfg(test)]
mod tests {
use crate::lit;
Expand All @@ -301,5 +360,26 @@ mod tests {
format!("{:?}", lit(1u32) % lit(2u32)),
"UInt32(1) % UInt32(2)"
);
assert_eq!(
format!("{:?}", lit(1u32) & lit(2u32)),
"UInt32(1) & UInt32(2)"
);
assert_eq!(
format!("{:?}", lit(1u32) | lit(2u32)),
"UInt32(1) | UInt32(2)"
);
assert_eq!(
format!("{:?}", lit(1u32) ^ lit(2u32)),
"UInt32(1) # UInt32(2)"
);
assert_eq!(
format!("{:?}", lit(1u32) << lit(2u32)),
"UInt32(1) << UInt32(2)"
);
assert_eq!(
format!("{:?}", lit(1u32) >> lit(2u32)),
"UInt32(1) >> UInt32(2)"
);
assert_eq!(format!("{:?}", -lit(1u32)), "(- UInt32(1))");
}
}
Loading