MCPcopy Create free account
hub / github.com/apache/datafusion / evaluate_predicate

Function evaluate_predicate

datafusion/physical-expr/src/expressions/case.rs:1420–1439  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

1418/// - `Some(false)` if the predicate evaluates to a falsy value.
1419/// - `None` if the predicate could not be evaluated.
1420fn 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
1441fn replace_with_null(
1442 expr: &Arc<dyn PhysicalExpr>,

Callers 1

nullableMethod · 0.85

Calls 6

newFunction · 0.85
emptyFunction · 0.50
evaluateMethod · 0.45
cast_toMethod · 0.45
as_refMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…