Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix null date args in range #14093

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading