Skip to content

Commit c80638b

Browse files
committed
Avoid some allocations
1 parent 3199c0d commit c80638b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

datafusion/functions-window/src/lead_lag.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,23 @@ fn parse_expr(
292292
})
293293
}
294294

295+
static NULL_FIELD: LazyLock<Field> =
296+
LazyLock::new(|| Field::new("value", DataType::Null, true));
297+
295298
/// Returns the field of the default value(if provided) when the
296299
/// expression is `NULL`.
297300
///
298301
/// Otherwise, returns the expression field unchanged.
299302
fn parse_expr_field(input_fields: &[Field]) -> Result<Field> {
300303
assert!(!input_fields.is_empty());
301-
let null_field = Field::new("value", DataType::Null, true);
302-
let expr_field = input_fields.first().unwrap_or(&null_field);
304+
let expr_field = input_fields.first().unwrap_or(&NULL_FIELD);
303305

304306
// Handles the most common case where NULL is unexpected
305307
if !expr_field.data_type().is_null() {
306308
return Ok(expr_field.clone().with_nullable(true));
307309
}
308310

309-
let default_value_field = input_fields.get(2).unwrap_or(&null_field);
311+
let default_value_field = input_fields.get(2).unwrap_or(&NULL_FIELD);
310312
Ok(default_value_field.clone().with_nullable(true))
311313
}
312314

0 commit comments

Comments
 (0)