liurenjie1024 commented on code in PR #169: URL: https://github.com/apache/iceberg-rust/pull/169#discussion_r1503555586
########## crates/iceberg/src/expr/predicate.rs: ########## @@ -20,43 +20,89 @@ //! `a > 10` is a predicate expression, and it evaluates to `true` if `a` is greater than `10`, use crate::expr::{BoundReference, PredicateOperator, UnboundReference}; -use crate::spec::Literal; +use crate::spec::Datum; use std::collections::HashSet; +use std::fmt::{Debug, Display, Formatter}; +use std::ops::Not; /// Logical expression, such as `AND`, `OR`, `NOT`. -pub struct LogicalExpression<T, const N: usize> { +#[derive(Debug)] +pub struct LogicalExpression<T: Debug, const N: usize> { inputs: [Box<T>; N], } +impl<T: Debug, const N: usize> LogicalExpression<T, N> { + fn new(inputs: [Box<T>; N]) -> Self { + Self { inputs } + } + + /// Return inputs of this logical expression. + pub fn inputs(&self) -> [&T; N] { + let mut ret: [&T; N] = [self.inputs[0].as_ref(); N]; + for (i, item) in ret.iter_mut().enumerate() { + *item = &self.inputs[i]; + } + ret + } +} + /// Unary predicate, for example, `a IS NULL`. -pub struct UnaryExpression<T> { +#[derive(Debug)] +pub struct UnaryExpression<T: Debug> { /// Operator of this predicate, must be single operand operator. op: PredicateOperator, /// Term of this predicate, for example, `a` in `a IS NULL`. term: T, } +impl<T: Display + Debug> Display for UnaryExpression<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {}", self.term, self.op) + } +} + +impl<T: Debug> UnaryExpression<T> { + pub(crate) fn new(op: PredicateOperator, term: T) -> Self { + Self { op, term } + } +} + /// Binary predicate, for example, `a > 10`. -pub struct BinaryExpression<T> { +#[derive(Debug)] +pub struct BinaryExpression<T: Debug> { /// Operator of this predicate, must be binary operator, such as `=`, `>`, `<`, etc. op: PredicateOperator, /// Term of this predicate, for example, `a` in `a > 10`. term: T, /// Literal of this predicate, for example, `10` in `a > 10`. - literal: Literal, + literal: Datum, +} + +impl<T: Debug> BinaryExpression<T> { + pub(crate) fn new(op: PredicateOperator, term: T, literal: Datum) -> Self { + Self { op, term, literal } + } +} + +impl<T: Display + Debug> Display for BinaryExpression<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {} {}", self.term, self.op, self.literal) + } } /// Set predicates, for example, `a in (1, 2, 3)`. -pub struct SetExpression<T> { +#[derive(Debug)] +pub struct SetExpression<T: Debug> { Review Comment: Good suggest, I just want to save implementation of `Debug`! ########## crates/iceberg/src/expr/predicate.rs: ########## @@ -20,43 +20,89 @@ //! `a > 10` is a predicate expression, and it evaluates to `true` if `a` is greater than `10`, use crate::expr::{BoundReference, PredicateOperator, UnboundReference}; -use crate::spec::Literal; +use crate::spec::Datum; use std::collections::HashSet; +use std::fmt::{Debug, Display, Formatter}; +use std::ops::Not; /// Logical expression, such as `AND`, `OR`, `NOT`. -pub struct LogicalExpression<T, const N: usize> { +#[derive(Debug)] +pub struct LogicalExpression<T: Debug, const N: usize> { inputs: [Box<T>; N], } +impl<T: Debug, const N: usize> LogicalExpression<T, N> { + fn new(inputs: [Box<T>; N]) -> Self { + Self { inputs } + } + + /// Return inputs of this logical expression. + pub fn inputs(&self) -> [&T; N] { + let mut ret: [&T; N] = [self.inputs[0].as_ref(); N]; + for (i, item) in ret.iter_mut().enumerate() { + *item = &self.inputs[i]; + } + ret + } +} + /// Unary predicate, for example, `a IS NULL`. -pub struct UnaryExpression<T> { +#[derive(Debug)] +pub struct UnaryExpression<T: Debug> { /// Operator of this predicate, must be single operand operator. op: PredicateOperator, /// Term of this predicate, for example, `a` in `a IS NULL`. term: T, } +impl<T: Display + Debug> Display for UnaryExpression<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {}", self.term, self.op) + } +} + +impl<T: Debug> UnaryExpression<T> { + pub(crate) fn new(op: PredicateOperator, term: T) -> Self { + Self { op, term } + } +} + /// Binary predicate, for example, `a > 10`. -pub struct BinaryExpression<T> { +#[derive(Debug)] +pub struct BinaryExpression<T: Debug> { /// Operator of this predicate, must be binary operator, such as `=`, `>`, `<`, etc. op: PredicateOperator, /// Term of this predicate, for example, `a` in `a > 10`. term: T, /// Literal of this predicate, for example, `10` in `a > 10`. - literal: Literal, + literal: Datum, +} + +impl<T: Debug> BinaryExpression<T> { + pub(crate) fn new(op: PredicateOperator, term: T, literal: Datum) -> Self { + Self { op, term, literal } + } +} + +impl<T: Display + Debug> Display for BinaryExpression<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {} {}", self.term, self.op, self.literal) + } } /// Set predicates, for example, `a in (1, 2, 3)`. -pub struct SetExpression<T> { +#[derive(Debug)] +pub struct SetExpression<T: Debug> { Review Comment: Good suggest, I just want to save implementation of `Debug`. -- 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