Skip to content

Commit 37ee8fa

Browse files
feniljainalamb
andauthored
fix: return NULL if any of the param to make_date is NULL (#16759)
* fix: return NULL if any of the param to make_date is NULL * fmt --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent fe45258 commit 37ee8fa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

datafusion/functions/src/datetime/make_date.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ impl ScalarUDFImpl for MakeDateFunc {
122122

123123
let [years, months, days] = take_function_args(self.name(), args)?;
124124

125+
if matches!(years, ColumnarValue::Scalar(ScalarValue::Null))
126+
|| matches!(months, ColumnarValue::Scalar(ScalarValue::Null))
127+
|| matches!(days, ColumnarValue::Scalar(ScalarValue::Null))
128+
{
129+
return Ok(ColumnarValue::Scalar(ScalarValue::Null));
130+
}
131+
125132
let years = years.cast_to(&Int32, None)?;
126133
let months = months.cast_to(&Int32, None)?;
127134
let days = days.cast_to(&Int32, None)?;
@@ -377,4 +384,19 @@ mod tests {
377384
"Arrow error: Cast error: Can't cast value 4294967295 to type Int32"
378385
);
379386
}
387+
388+
#[test]
389+
fn test_make_date_null_param() {
390+
let res = invoke_make_date_with_args(
391+
vec![
392+
ColumnarValue::Scalar(ScalarValue::Null),
393+
ColumnarValue::Scalar(ScalarValue::Int64(Some(1))),
394+
ColumnarValue::Scalar(ScalarValue::UInt32(Some(14))),
395+
],
396+
1,
397+
)
398+
.expect("that make_date parsed values without error");
399+
400+
assert!(matches!(res, ColumnarValue::Scalar(ScalarValue::Null)));
401+
}
380402
}

0 commit comments

Comments
 (0)