Attempts to const evaluate the given `predicate`. Returns: - `Some(true)` if the predicate evaluates to a truthy value. - `Some(false)` if the predicate evaluates to a falsy value. - `None` if the predicate could not be evaluated.
(predicate: &Arc<dyn PhysicalExpr>)
| 1418 | /// - `Some(false)` if the predicate evaluates to a falsy value. |
| 1419 | /// - `None` if the predicate could not be evaluated. |
| 1420 | fn evaluate_predicate(predicate: &Arc<dyn PhysicalExpr>) -> Result<Option<bool>> { |
| 1421 | // Create a dummy record with no columns and one row |
| 1422 | let batch = RecordBatch::try_new_with_options( |
| 1423 | Arc::new(Schema::empty()), |
| 1424 | vec![], |
| 1425 | &RecordBatchOptions::new().with_row_count(Some(1)), |
| 1426 | )?; |
| 1427 | |
| 1428 | // Evaluate the predicate and interpret the result as a boolean |
| 1429 | let result = match predicate.evaluate(&batch) { |
| 1430 | // An error during evaluation means we couldn't const evaluate the predicate, so return `None` |
| 1431 | Err(_) => None, |
| 1432 | Ok(ColumnarValue::Array(array)) => Some( |
| 1433 | ScalarValue::try_from_array(array.as_ref(), 0)? |
| 1434 | .cast_to(&DataType::Boolean)?, |
| 1435 | ), |
| 1436 | Ok(ColumnarValue::Scalar(scalar)) => Some(scalar.cast_to(&DataType::Boolean)?), |
| 1437 | }; |
| 1438 | Ok(result.map(|v| matches!(v, ScalarValue::Boolean(Some(true))))) |
| 1439 | } |
| 1440 | |
| 1441 | fn replace_with_null( |
| 1442 | expr: &Arc<dyn PhysicalExpr>, |