@@ -46,7 +46,7 @@ impl<T: Debug, const N: usize> Debug for LogicalExpression<T, N> {
4646}
4747
4848impl < T , const N : usize > LogicalExpression < T , N > {
49- fn new ( inputs : [ Box < T > ; N ] ) -> Self {
49+ pub ( crate ) fn new ( inputs : [ Box < T > ; N ] ) -> Self {
5050 Self { inputs }
5151 }
5252
8282#[ derive( PartialEq ) ]
8383pub struct UnaryExpression < T > {
8484 /// Operator of this predicate, must be single operand operator.
85- op : PredicateOperator ,
85+ pub ( crate ) op : PredicateOperator ,
8686 /// Term of this predicate, for example, `a` in `a IS NULL`.
87- term : T ,
87+ pub ( crate ) term : T ,
8888}
8989
9090impl < T : Debug > Debug for UnaryExpression < T > {
@@ -116,13 +116,17 @@ impl<T> UnaryExpression<T> {
116116 debug_assert ! ( op. is_unary( ) ) ;
117117 Self { op, term }
118118 }
119+
120+ pub ( crate ) fn field_id ( & self ) -> i32 {
121+ self . term . field ( ) . id
122+ }
119123}
120124
121125/// Binary predicate, for example, `a > 10`.
122126#[ derive( PartialEq ) ]
123127pub struct BinaryExpression < T > {
124128 /// Operator of this predicate, must be binary operator, such as `=`, `>`, `<`, etc.
125- op : PredicateOperator ,
129+ pub ( crate ) op : PredicateOperator ,
126130 /// Term of this predicate, for example, `a` in `a > 10`.
127131 term : T ,
128132 /// Literal of this predicate, for example, `10` in `a > 10`.
@@ -144,6 +148,10 @@ impl<T> BinaryExpression<T> {
144148 debug_assert ! ( op. is_binary( ) ) ;
145149 Self { op, term, literal }
146150 }
151+
152+ pub ( crate ) fn field_id ( & self ) -> i32 {
153+ self . term . field ( ) . id
154+ }
147155}
148156
149157impl < T : Display > Display for BinaryExpression < T > {
@@ -165,7 +173,7 @@ impl<T: Bind> Bind for BinaryExpression<T> {
165173#[ derive( PartialEq ) ]
166174pub struct SetExpression < T > {
167175 /// Operator of this predicate, must be set operator, such as `IN`, `NOT IN`, etc.
168- op : PredicateOperator ,
176+ pub ( crate ) op : PredicateOperator ,
169177 /// Term of this predicate, for example, `a` in `a in (1, 2, 3)`.
170178 term : T ,
171179 /// Literals of this predicate, for example, `(1, 2, 3)` in `a in (1, 2, 3)`.
@@ -187,6 +195,10 @@ impl<T> SetExpression<T> {
187195 debug_assert ! ( op. is_set( ) ) ;
188196 Self { op, term, literals }
189197 }
198+
199+ pub ( crate ) fn field_id ( & self ) -> i32 {
200+ self . term . field ( ) . id
201+ }
190202}
191203
192204impl < T : Bind > Bind for SetExpression < T > {
@@ -209,6 +221,9 @@ impl<T: Display + Debug> Display for SetExpression<T> {
209221/// Unbound predicate expression before binding to a schema.
210222#[ derive( Debug , PartialEq ) ]
211223pub enum Predicate {
224+ AlwaysTrue ,
225+ AlwaysFalse ,
226+
212227 /// And predicate, for example, `a > 10 AND b < 20`.
213228 And ( LogicalExpression < Predicate , 2 > ) ,
214229 /// Or predicate, for example, `a > 10 OR b < 20`.
@@ -366,6 +381,12 @@ impl Bind for Predicate {
366381impl Display for Predicate {
367382 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
368383 match self {
384+ Predicate :: AlwaysTrue => {
385+ write ! ( f, "TRUE" )
386+ }
387+ Predicate :: AlwaysFalse => {
388+ write ! ( f, "FALSE" )
389+ }
369390 Predicate :: And ( expr) => {
370391 write ! ( f, "({}) AND ({})" , expr. inputs( ) [ 0 ] , expr. inputs( ) [ 1 ] )
371392 }
@@ -453,6 +474,8 @@ impl Predicate {
453474 /// ```
454475 pub fn negate ( self ) -> Predicate {
455476 match self {
477+ Predicate :: AlwaysTrue => Predicate :: AlwaysFalse ,
478+ Predicate :: AlwaysFalse => Predicate :: AlwaysTrue ,
456479 Predicate :: And ( expr) => Predicate :: Or ( LogicalExpression :: new (
457480 expr. inputs . map ( |expr| Box :: new ( expr. negate ( ) ) ) ,
458481 ) ) ,
@@ -599,6 +622,14 @@ impl Display for BoundPredicate {
599622 }
600623}
601624
625+ pub ( crate ) trait PredicateVisitor < T > {
626+ fn visit ( predicate : Predicate ) -> T ;
627+ }
628+
629+ pub ( crate ) trait BoundPredicateVisitor < T > {
630+ fn visit ( predicate : BoundPredicate ) -> T ;
631+ }
632+
602633#[ cfg( test) ]
603634mod tests {
604635 use std:: ops:: Not ;
0 commit comments