@@ -116,6 +116,14 @@ impl<T> UnaryExpression<T> {
116116 debug_assert ! ( op. is_unary( ) ) ;
117117 Self { op, term }
118118 }
119+
120+ pub ( crate ) fn term ( & self ) -> & T {
121+ & self . term
122+ }
123+
124+ pub ( crate ) fn op ( & self ) -> & PredicateOperator {
125+ & self . op
126+ }
119127}
120128
121129/// Binary predicate, for example, `a > 10`.
@@ -144,6 +152,18 @@ impl<T> BinaryExpression<T> {
144152 debug_assert ! ( op. is_binary( ) ) ;
145153 Self { op, term, literal }
146154 }
155+
156+ pub ( crate ) fn term ( & self ) -> & T {
157+ & self . term
158+ }
159+
160+ pub ( crate ) fn op ( & self ) -> & PredicateOperator {
161+ & self . op
162+ }
163+
164+ pub ( crate ) fn literal ( & self ) -> & Datum {
165+ & self . literal
166+ }
147167}
148168
149169impl < T : Display > Display for BinaryExpression < T > {
@@ -191,6 +211,18 @@ impl<T> SetExpression<T> {
191211 debug_assert ! ( op. is_set( ) ) ;
192212 Self { op, term, literals }
193213 }
214+
215+ pub ( crate ) fn term ( & self ) -> & T {
216+ & self . term
217+ }
218+
219+ pub ( crate ) fn op ( & self ) -> & PredicateOperator {
220+ & self . op
221+ }
222+
223+ pub ( crate ) fn literals ( & self ) -> & FnvHashSet < Datum > {
224+ & self . literals
225+ }
194226}
195227
196228impl < T : Bind > Bind for SetExpression < T > {
@@ -217,6 +249,10 @@ impl<T: Display + Debug> Display for SetExpression<T> {
217249/// Unbound predicate expression before binding to a schema.
218250#[ derive( Debug , PartialEq ) ]
219251pub enum Predicate {
252+ /// AlwaysTrue predicate, for example, `TRUE`.
253+ AlwaysTrue ,
254+ /// AlwaysFalse predicate, for example, `FALSE`.
255+ AlwaysFalse ,
220256 /// And predicate, for example, `a > 10 AND b < 20`.
221257 And ( LogicalExpression < Predicate , 2 > ) ,
222258 /// Or predicate, for example, `a > 10 OR b < 20`.
@@ -367,13 +403,21 @@ impl Bind for Predicate {
367403 bound_literals,
368404 ) ) )
369405 }
406+ Predicate :: AlwaysTrue => Ok ( BoundPredicate :: AlwaysTrue ) ,
407+ Predicate :: AlwaysFalse => Ok ( BoundPredicate :: AlwaysFalse ) ,
370408 }
371409 }
372410}
373411
374412impl Display for Predicate {
375413 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
376414 match self {
415+ Predicate :: AlwaysTrue => {
416+ write ! ( f, "TRUE" )
417+ }
418+ Predicate :: AlwaysFalse => {
419+ write ! ( f, "FALSE" )
420+ }
377421 Predicate :: And ( expr) => {
378422 write ! ( f, "({}) AND ({})" , expr. inputs( ) [ 0 ] , expr. inputs( ) [ 1 ] )
379423 }
@@ -461,6 +505,8 @@ impl Predicate {
461505 /// ```
462506 pub fn negate ( self ) -> Predicate {
463507 match self {
508+ Predicate :: AlwaysTrue => Predicate :: AlwaysFalse ,
509+ Predicate :: AlwaysFalse => Predicate :: AlwaysTrue ,
464510 Predicate :: And ( expr) => Predicate :: Or ( LogicalExpression :: new (
465511 expr. inputs . map ( |expr| Box :: new ( expr. negate ( ) ) ) ,
466512 ) ) ,
@@ -525,6 +571,8 @@ impl Predicate {
525571 Predicate :: Unary ( expr) => Predicate :: Unary ( expr) ,
526572 Predicate :: Binary ( expr) => Predicate :: Binary ( expr) ,
527573 Predicate :: Set ( expr) => Predicate :: Set ( expr) ,
574+ Predicate :: AlwaysTrue => Predicate :: AlwaysTrue ,
575+ Predicate :: AlwaysFalse => Predicate :: AlwaysFalse ,
528576 }
529577 }
530578}
0 commit comments