Skip to content

Commit

Permalink
fix null dates in range
Browse files Browse the repository at this point in the history
  • Loading branch information
cht42 committed Jan 12, 2025
1 parent 17446ad commit f0fd009
Show file tree
Hide file tree
Showing 2 changed files with 29 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
15 changes: 15 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -6201,6 +6201,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 f0fd009

Please sign in to comment.