liurenjie1024 commented on code in PR #169: URL: https://github.com/apache/iceberg-rust/pull/169#discussion_r1505227423
########## crates/iceberg/src/expr/mod.rs: ########## @@ -64,3 +71,73 @@ impl Display for PredicateOperator { } } } + +impl PredicateOperator { + /// Check if this operator is unary operator. + /// + /// # Example + /// + /// ```rust + /// use iceberg::expr::PredicateOperator; + /// assert!(PredicateOperator::IsNull.unary()); + /// ``` + pub fn unary(self) -> bool { + (self as u16) < (PredicateOperator::LessThan as u16) + } + + /// Check if this operator is binary operator. + /// + /// # Example + /// + /// ```rust + /// use iceberg::expr::PredicateOperator; + /// assert!(PredicateOperator::LessThan.binary()); + /// ``` + pub fn binary(self) -> bool { + ((self as u16) > (PredicateOperator::NotNan as u16)) + && ((self as u16) < (PredicateOperator::In as u16)) + } + + /// Check if this operator is set operator. + /// + /// # Example + /// + /// ```rust + /// use iceberg::expr::PredicateOperator; + /// assert!(PredicateOperator::In.set()); + /// ``` + pub fn set(self) -> bool { + (self as u16) > (PredicateOperator::NotStartsWith as u16) + } +} + +#[cfg(test)] +mod tests { + use crate::expr::PredicateOperator; + + #[test] + fn test_unary() { + assert!(PredicateOperator::IsNull.unary()); + assert!(PredicateOperator::NotNull.unary()); + assert!(PredicateOperator::IsNan.unary()); + assert!(PredicateOperator::NotNan.unary()); + } + + #[test] + fn test_binary() { + assert!(PredicateOperator::LessThan.binary()); + assert!(PredicateOperator::LessThanOrEq.binary()); + assert!(PredicateOperator::GreaterThan.binary()); + assert!(PredicateOperator::GreaterThanOrEq.binary()); + assert!(PredicateOperator::Eq.binary()); + assert!(PredicateOperator::NotEq.binary()); + assert!(PredicateOperator::StartsWith.binary()); + assert!(PredicateOperator::NotStartsWith.binary()); + } + + #[test] + fn test_set() { + assert!(PredicateOperator::In.set()); Review Comment: Yes, adding `is_` prefix better matches rust's naming convention. The `_op` suffix seems redundant, so I've changed them to `is_set`. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org