liurenjie1024 commented on code in PR #169: URL: https://github.com/apache/iceberg-rust/pull/169#discussion_r1506861883
########## crates/iceberg/src/expr/term.rs: ########## @@ -17,21 +17,89 @@ //! Term definition. -use crate::spec::NestedFieldRef; +use crate::expr::{BinaryExpression, Predicate, PredicateOperator}; +use crate::spec::{Datum, NestedField, NestedFieldRef}; +use std::fmt::{Display, Formatter}; /// Unbound term before binding to a schema. -pub type UnboundTerm = UnboundReference; +pub type Term = Reference; /// A named reference in an unbound expression. /// For example, `a` in `a > 10`. -pub struct UnboundReference { +#[derive(Debug, Clone)] +pub struct Reference { name: String, } +impl Reference { + /// Create a new unbound reference. + pub fn new(name: impl Into<String>) -> Self { + Self { name: name.into() } + } + + /// Return the name of this reference. + pub fn name(&self) -> &str { + &self.name + } +} + +impl Reference { + /// Creates an less than expression. For example, `a < 10`. + /// + /// # Example + /// + /// ```rust + /// + /// use iceberg::expr::Reference; + /// use iceberg::spec::Datum; + /// let expr = Reference::new("a").less_than(Datum::long(10)); + /// + /// assert_eq!(&format!("{expr}"), "a < 10"); + /// ``` + pub fn less_than(self, datum: Datum) -> Predicate { + Predicate::Binary(BinaryExpression::new( + PredicateOperator::LessThan, + self, + datum, + )) + } Review Comment: Yes, we will need more like this. But I prefer to leave them as good first issues for new contributors. -- 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