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],
)
| 341 | /// |
| 342 | /// For more details see: <https://github.com/apache/datafusion/issues/12717> |
| 343 | fn 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 | |
| 365 | static NULL_FIELD: LazyLock<FieldRef> = |
| 366 | LazyLock::new(|| Field::new("value", DataType::Null, true).into()); |