Skip to content

Commit

Permalink
fix null date args in range (#14093)
Browse files Browse the repository at this point in the history
* fix null dates in range

* fix

---------

Co-authored-by: Cyprien Huet <[email protected]>
  • Loading branch information
cht42 and Cyprien Huet authored Jan 13, 2025
1 parent e8cac16 commit 63b94c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
16 changes: 14 additions & 2 deletions datafusion/functions-nested/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,29 @@ fn gen_range_date(args: &[ArrayRef], include_upper_bound: bool) -> Result<ArrayR
let values_builder = Date32Builder::new();
let mut list_builder = ListBuilder::new(values_builder);

for (idx, stop) in stop_array.iter().enumerate() {
let mut stop = stop.unwrap_or(0);
for idx in 0..stop_array.len() {
if stop_array.is_null(idx) {
list_builder.append_null();
continue;
}
let mut stop = stop_array.value(idx);

let start = if let Some(start_array_values) = start_array {
if start_array_values.is_null(idx) {
list_builder.append_null();
continue;
}
start_array_values.value(idx)
} else {
list_builder.append_null();
continue;
};

let step = if let Some(step) = step_array {
if step.is_null(idx) {
list_builder.append_null();
continue;
}
step.value(idx)
} else {
list_builder.append_null();
Expand Down
30 changes: 30 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -6091,6 +6091,21 @@ select range(NULL, DATE '1993-03-01', INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(NULL::Date, DATE '1993-03-01', INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(DATE '1993-03-01', NULL::Date, INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(DATE '1993-02-01', DATE '1993-03-01', NULL::Interval);
----
NULL

query ?
select range(NULL, TIMESTAMP '1993-03-01', INTERVAL '1' YEAR);
----
Expand Down Expand Up @@ -6201,6 +6216,21 @@ select generate_series(NULL, DATE '1993-03-01', INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(NULL::Date, DATE '1993-03-01', INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(DATE '1993-03-01', NULL::Date, INTERVAL '1' YEAR);
----
NULL

query ?
select generate_series(DATE '1993-02-01', DATE '1993-03-01', NULL::Interval);
----
NULL

query ?
select generate_series(NULL, TIMESTAMP '1993-03-01', INTERVAL '1' YEAR);
----
Expand Down

0 comments on commit 63b94c8

Please sign in to comment.