Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions datafusion/functions-nested/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ fn array_remove_internal(
let list_array = array.as_list::<i64>();
general_remove::<i64>(list_array, element_array, arr_n)
}
DataType::Null => Ok(new_null_array(array.data_type(), array.len())),
array_type => {
exec_err!("array_remove_all does not support type '{array_type}'.")
}
Expand All @@ -425,6 +426,7 @@ fn array_remove_with_scalar_args(
let list_array = array.as_list::<i64>();
general_remove_with_scalar::<i64>(list_array, scalar_needle, max_removals)
}
DataType::Null => Ok(new_null_array(array.data_type(), array.len())),
array_type => exec_err!(
"array_remove/array_remove_n/array_remove_all does not support type '{array_type}'."
),
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-nested/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fn array_replace_with_scalar_args(
let list = list_array.as_list::<i64>();
general_replace_with_scalar::<i64>(list, &needle, scalar_to, max_replacements)
}
DataType::Null => Ok(new_null_array(list_array.data_type(), 1)),
DataType::Null => Ok(new_null_array(list_array.data_type(), list_array.len())),
array_type => exec_err!("array_replace does not support type '{array_type}'."),
}
}
Expand All @@ -651,7 +651,7 @@ fn array_replace_internal(
let list_array = array.as_list::<i64>();
general_replace::<i64>(list_array, from, to, arr_n)
}
DataType::Null => Ok(new_null_array(array.data_type(), 1)),
DataType::Null => Ok(new_null_array(array.data_type(), array.len())),
array_type => exec_err!("array_replace does not support type '{array_type}'."),
}
}
Expand Down
35 changes: 30 additions & 5 deletions datafusion/sqllogictest/test_files/array/array_remove.slt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,36 @@ select

#TODO: https://github.com/apache/datafusion/issues/7142

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need to address this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULL handling looks complete here, this comment can be cleaned up. #7142 is still tracked in other files, so we're not losing the reference.

# follow PostgreSQL behavior
#query ?
#select
# array_remove(NULL, 1)
#----
#NULL
# A NULL-typed array argument returns NULL, matching array_replace and SQL
# three-valued logic.
query ?
select array_remove(NULL, 1);
----
NULL

query ?
select array_remove_n(NULL, 1, 2);
----
NULL

query ?
select array_remove_all(NULL, 1);
----
NULL

query ?
select array_remove(column1, 1) from (values (NULL), (NULL), (NULL));
----
NULL
NULL
NULL

query ?
select array_remove(column1, column2) from (values (NULL, 1), (NULL, 2), (NULL, 3)) as t(column1, column2);
----
NULL
NULL
NULL

query ??
select
Expand Down
31 changes: 31 additions & 0 deletions datafusion/sqllogictest/test_files/array/array_replace.slt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ select array_replace(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'),
----
[1, 2, 3, 4, 5]

# A NULL-typed array argument returns NULL, for both literal and multi-row
# column inputs.
query ?
select array_replace(NULL, 1, 2);
----
NULL

query ?
select array_replace_n(NULL, 1, 2, 3);
----
NULL

query ?
select array_replace_all(NULL, 1, 2);
----
NULL

query ?
select array_replace(column1, 1, 2) from (values (NULL), (NULL), (NULL));
----
NULL
NULL
NULL

query ?
select array_replace(column1, column2, column3) from (values (NULL, 1, 2), (NULL, 3, 4), (NULL, 5, 6)) as t(column1, column2, column3);
----
NULL
NULL
NULL

# array_replace scalar function with columns #1
query ?
select array_replace(column1, column2, column3) from arrays_with_repeating_elements;
Expand Down
Loading