rluvaton commented on code in PR #27471:
URL: https://github.com/apache/datafusion/pull/27471#discussion_r4590679732


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1194,6 +1185,71 @@ impl BinaryExpr {
         }
     }
 
+    /// Evaluates the RHS of `OR` only on the rows selected by `mask` (the rows
+    /// whose result depends on the RHS); the other rows are `fill_value`.
+    fn evaluate_pre_selection(
+        &self,
+        batch: &RecordBatch,
+        lhs: ColumnarValue,
+        mask: &BooleanArray,
+        fill_value: bool,
+    ) -> Result<ColumnarValue> {
+        // Use `filter_record_batch` directly because `evaluate_selection`
+        // scatters the RHS back to the original batch length.
+        let selection_batch = filter_record_batch(batch, mask)?;
+        let right_ret = self.right.evaluate(&selection_batch)?;
+
+        match &right_ret {
+            ColumnarValue::Array(array) => {
+                let boolean_array = array.as_boolean();
+                // If the RHS is uniform on the selected rows, the whole
+                // expression collapses and no scatter is needed.
+                if boolean_array.null_count() == 0 {
+                    let rhs_value = if !boolean_array.has_false() {
+                        Some(true)
+                    } else if !boolean_array.has_true() {
+                        Some(false)
+                    } else {
+                        None
+                    };
+                    if let Some(rhs_value) = rhs_value {
+                        return Ok(uniform_pre_selection_result(
+                            rhs_value, fill_value, lhs,
+                        ));
+                    }
+                }
+
+                let scattered =
+                    pre_selection_scatter(mask, Some(boolean_array), 
fill_value)?;
+                // Selected rows may have a NULL LHS (`NULL OR x`), so combine
+                // with the LHS; unselected rows are `fill_value` on both 
sides.
+                if lhs.data_type() == DataType::Boolean

Review Comment:
   Dropped the data type check
   
   `fill_value` already exists here I just moved it and I want to avoid other 
changes in this pr but it can be done in a different one.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to