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

Function parse_expr

datafusion/functions-window/src/lead_lag.rs:343–363  ·  view source on GitHub ↗

When `lead`/`lag` is evaluated on a `NULL` expression we attempt to refine it by matching it with the type of the default value. For e.g. in `lead(NULL, 1, false)` the generic `ScalarValue::Null` is refined into `ScalarValue::Boolean(None)`. Only the type is refined, the expression value remains `NULL`. When the window function is evaluated with `NULL` expression this guarantees that the type ma

(
    input_exprs: &[Arc<dyn PhysicalExpr>],
    input_fields: &[FieldRef],
)

Source from the content-addressed store, hash-verified

341///
342/// For more details see: <https://github.com/apache/datafusion/issues/12717>
343fn parse_expr(
344 input_exprs: &[Arc<dyn PhysicalExpr>],
345 input_fields: &[FieldRef],
346) -> Result<Arc<dyn PhysicalExpr>> {
347 assert!(!input_exprs.is_empty());
348 assert!(!input_fields.is_empty());
349
350 let expr = Arc::clone(input_exprs.first().unwrap());
351 let expr_field = input_fields.first().unwrap();
352
353 // Handles the most common case where NULL is unexpected
354 if !expr_field.data_type().is_null() {
355 return Ok(expr);
356 }
357
358 let default_value = get_scalar_value_from_args(input_exprs, 2)?;
359 default_value.map_or(Ok(expr), |value| {
360 ScalarValue::try_from(&value.data_type())
361 .map(|v| Arc::new(expressions::Literal::new(v)) as Arc<dyn PhysicalExpr>)
362 })
363}
364
365static NULL_FIELD: LazyLock<FieldRef> =
366 LazyLock::new(|| Field::new("value", DataType::Null, true).into());

Callers 2

expressionsMethod · 0.70

Calls 6

newFunction · 0.85
firstMethod · 0.45
is_nullMethod · 0.45
data_typeMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…