@@ -119,6 +119,10 @@ impl<T> UnaryExpression<T> {
119119 pub ( crate ) fn op ( & self ) -> PredicateOperator {
120120 self . op
121121 }
122+
123+ pub ( crate ) fn term ( & self ) -> & T {
124+ & self . term
125+ }
122126}
123127
124128/// Binary predicate, for example, `a > 10`.
@@ -147,12 +151,17 @@ impl<T> BinaryExpression<T> {
147151 debug_assert ! ( op. is_binary( ) ) ;
148152 Self { op, term, literal }
149153 }
154+
150155 pub ( crate ) fn op ( & self ) -> PredicateOperator {
151156 self . op
152157 }
153158 pub ( crate ) fn literal ( & self ) -> & Datum {
154159 & self . literal
155160 }
161+
162+ pub ( crate ) fn term ( & self ) -> & T {
163+ & self . term
164+ }
156165}
157166
158167impl < T : Display > Display for BinaryExpression < T > {
@@ -200,12 +209,17 @@ impl<T> SetExpression<T> {
200209 debug_assert ! ( op. is_set( ) ) ;
201210 Self { op, term, literals }
202211 }
212+
203213 pub ( crate ) fn op ( & self ) -> PredicateOperator {
204214 self . op
205215 }
206216 pub ( crate ) fn literals ( & self ) -> & FnvHashSet < Datum > {
207217 & self . literals
208218 }
219+
220+ pub ( crate ) fn term ( & self ) -> & T {
221+ & self . term
222+ }
209223}
210224
211225impl < T : Bind > Bind for SetExpression < T > {
@@ -232,6 +246,10 @@ impl<T: Display + Debug> Display for SetExpression<T> {
232246/// Unbound predicate expression before binding to a schema.
233247#[ derive( Debug , PartialEq ) ]
234248pub enum Predicate {
249+ /// AlwaysTrue predicate, for example, `TRUE`.
250+ AlwaysTrue ,
251+ /// AlwaysFalse predicate, for example, `FALSE`.
252+ AlwaysFalse ,
235253 /// And predicate, for example, `a > 10 AND b < 20`.
236254 And ( LogicalExpression < Predicate , 2 > ) ,
237255 /// Or predicate, for example, `a > 10 OR b < 20`.
@@ -382,13 +400,21 @@ impl Bind for Predicate {
382400 bound_literals,
383401 ) ) )
384402 }
403+ Predicate :: AlwaysTrue => Ok ( BoundPredicate :: AlwaysTrue ) ,
404+ Predicate :: AlwaysFalse => Ok ( BoundPredicate :: AlwaysFalse ) ,
385405 }
386406 }
387407}
388408
389409impl Display for Predicate {
390410 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
391411 match self {
412+ Predicate :: AlwaysTrue => {
413+ write ! ( f, "TRUE" )
414+ }
415+ Predicate :: AlwaysFalse => {
416+ write ! ( f, "FALSE" )
417+ }
392418 Predicate :: And ( expr) => {
393419 write ! ( f, "({}) AND ({})" , expr. inputs( ) [ 0 ] , expr. inputs( ) [ 1 ] )
394420 }
@@ -476,6 +502,8 @@ impl Predicate {
476502 /// ```
477503 pub fn negate ( self ) -> Predicate {
478504 match self {
505+ Predicate :: AlwaysTrue => Predicate :: AlwaysFalse ,
506+ Predicate :: AlwaysFalse => Predicate :: AlwaysTrue ,
479507 Predicate :: And ( expr) => Predicate :: Or ( LogicalExpression :: new (
480508 expr. inputs . map ( |expr| Box :: new ( expr. negate ( ) ) ) ,
481509 ) ) ,
@@ -540,6 +568,8 @@ impl Predicate {
540568 Predicate :: Unary ( expr) => Predicate :: Unary ( expr) ,
541569 Predicate :: Binary ( expr) => Predicate :: Binary ( expr) ,
542570 Predicate :: Set ( expr) => Predicate :: Set ( expr) ,
571+ Predicate :: AlwaysTrue => Predicate :: AlwaysTrue ,
572+ Predicate :: AlwaysFalse => Predicate :: AlwaysFalse ,
543573 }
544574 }
545575}
0 commit comments