@@ -1107,20 +1107,49 @@ fn split_binary_impl<'a>(
1107
1107
/// assert_eq!(conjunction(split), Some(expr));
1108
1108
/// ```
1109
1109
pub fn conjunction ( filters : impl IntoIterator < Item = Expr > ) -> Option < Expr > {
1110
- filters. into_iter ( ) . reduce ( |accum , expr| accum . and ( expr ) )
1110
+ filters. into_iter ( ) . reduce ( Expr :: and)
1111
1111
}
1112
1112
1113
1113
/// Combines an array of filter expressions into a single filter
1114
1114
/// expression consisting of the input filter expressions joined with
1115
1115
/// logical OR.
1116
1116
///
1117
1117
/// Returns None if the filters array is empty.
1118
+ ///
1119
+ /// # Example
1120
+ /// ```
1121
+ /// # use datafusion_expr::{col, lit};
1122
+ /// # use datafusion_expr::utils::disjunction;
1123
+ /// // a=1 OR b=2
1124
+ /// let expr = col("a").eq(lit(1)).or(col("b").eq(lit(2)));
1125
+ ///
1126
+ /// // [a=1, b=2]
1127
+ /// let split = vec![
1128
+ /// col("a").eq(lit(1)),
1129
+ /// col("b").eq(lit(2)),
1130
+ /// ];
1131
+ ///
1132
+ /// // use disjuncton to join them together with `OR`
1133
+ /// assert_eq!(disjunction(split), Some(expr));
1134
+ /// ```
1118
1135
pub fn disjunction ( filters : impl IntoIterator < Item = Expr > ) -> Option < Expr > {
1119
- filters. into_iter ( ) . reduce ( |accum , expr| accum . or ( expr ) )
1136
+ filters. into_iter ( ) . reduce ( Expr :: or )
1120
1137
}
1121
1138
1122
- /// returns a new [LogicalPlan] that wraps `plan` in a [LogicalPlan::Filter] with
1123
- /// its predicate be all `predicates` ANDed.
1139
+ /// Returns a new [LogicalPlan] that filters the output of `plan` with a
1140
+ /// [LogicalPlan::Filter] with all `predicates` ANDed.
1141
+ ///
1142
+ /// # Example
1143
+ /// Before:
1144
+ /// ```text
1145
+ /// plan
1146
+ /// ```
1147
+ ///
1148
+ /// After:
1149
+ /// ```text
1150
+ /// Filter(predicate)
1151
+ /// plan
1152
+ /// ```
1124
1153
pub fn add_filter ( plan : LogicalPlan , predicates : & [ & Expr ] ) -> Result < LogicalPlan > {
1125
1154
// reduce filters to a single filter with an AND
1126
1155
let predicate = predicates
0 commit comments