rluvaton commented on code in PR #27471:
URL: https://github.com/apache/datafusion/pull/27471#discussion_r4663263751
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -556,69 +583,36 @@ impl PhysicalExpr for BinaryExpr {
let lhs = self.left.evaluate(batch)?;
// Check if we can apply short-circuit evaluation.
- match check_short_circuit(&lhs, &self.op) {
- ShortCircuitStrategy::None => {}
- ShortCircuitStrategy::ReturnLeft => return Ok(lhs),
- ShortCircuitStrategy::ReturnRight => {
- let rhs = self.right.evaluate(batch)?;
- return Ok(rhs);
- }
- ShortCircuitStrategy::PreSelection { mask, fill_value } => {
- // `mask` selects the rows whose result depends on the RHS; the
- // unselected rows are all `fill_value` (see
`ShortCircuitStrategy`).
- //
- // 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,
- ));
- }
- }
-
- return pre_selection_scatter(
- &mask,
- Some(boolean_array),
- fill_value,
- );
- }
- ColumnarValue::Scalar(scalar) => {
- if let ScalarValue::Boolean(v) = scalar {
- // A scalar RHS applies uniformly to all selected
rows.
- if let Some(v) = v {
- return Ok(uniform_pre_selection_result(
- *v, fill_value, lhs,
- ));
- } else {
- return pre_selection_scatter(&mask, None,
fill_value);
- }
- } else {
- return internal_err!(
- "Expected boolean scalar value, found:
{right_ret:?}"
- );
- }
- }
+ if self.op == Operator::Or {
+ match check_short_circuit_for_or(&lhs, self.right_is_volatile()) {
+ ShortCircuitStrategy::None => {}
+ ShortCircuitStrategy::ReturnLeft => return Ok(lhs),
+ ShortCircuitStrategy::ReturnRight => {
+ let rhs = self.right.evaluate(batch)?;
+ return Ok(rhs);
+ }
+ ShortCircuitStrategy::PreSelection { mask, fill_value } => {
+ return self.evaluate_pre_selection(batch, lhs, &mask,
fill_value);
}
}
}
- let rhs = self.right.evaluate(batch)?;
+ let rhs = match self.right.evaluate(batch) {
+ Ok(rhs) => rhs,
+ // A deterministic RHS may fail on rows the LHS already decided
+ // (e.g. `x = 0 OR 1 / x > 1`), so retry on the undecided rows
only.
+ Err(e) if self.op == Operator::Or => {
Review Comment:
will do as a follow up
--
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]