timsaucer commented on code in PR #24365:
URL: https://github.com/apache/datafusion/pull/24365#discussion_r3785748145
##########
datafusion/functions-nested/src/replace.rs:
##########
@@ -367,6 +397,24 @@ impl ScalarUDFImpl for ArrayReplaceAll {
}
}
+/// Return field shared by `array_replace`, `array_replace_n` and
+/// `array_replace_all`: the input list type, except that its inner field is
+/// nullable whenever the replacement element may be null.
+fn replace_return_field(name: &str, arg_fields: &[FieldRef]) ->
Result<FieldRef> {
+ // `array` is at index 0 and `to` at index 2 for all three functions.
+ // `from` never contributes values to the output, so `to` is the only
+ // argument besides `array` that can affect the output's type.
+ let [array_field, _from_field, to_field, ..] = arg_fields else {
Review Comment:
Yes, exactly. `from` is only used to find the replacement match. It cannot
impact the output. The one place this may seem non-obvious is the case where
you have an array that is not nullable, and you have a `from` that is null and
a `to` that is not nullable. The output remains a non-nullable list.
```
> set datafusion.format.types_info = true;
0 row(s) fetched.
Elapsed 0.002 seconds.
> select array_replace(arrow_cast(column1, 'List(non-null Int64)'), NULL, 3)
from values (make_array(1, 2, 2));
+-------------------------------------------------------------------------------+
| array_replace(arrow_cast(column1,Utf8("List(non-null
Int64)")),NULL,Int64(3)) |
| List(non-null Int64)
|
+-------------------------------------------------------------------------------+
| [1, 2, 2]
|
+-------------------------------------------------------------------------------+
1 row(s) fetched.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]