Skip to content

Commit 646d183

Browse files
authored
docs: clarify NULL handling for array_remove functions (#21014) (#21018)
## Summary - clarify how `array_remove`, `array_remove_n`, and `array_remove_all` behave when the input array contains `NULL` values - document that a `NULL` `element` argument returns `NULL` instead of removing `NULL` entries from the array - add examples that show existing `NULL` array elements are preserved when removing a non-`NULL` value ## Testing - docs-only change, no code paths changed Closes #21014
1 parent 93724b0 commit 646d183

File tree

3 files changed

+93
-51
lines changed

3 files changed

+93
-51
lines changed

datafusion/functions-nested/src/remove.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ make_udf_expr_and_func!(
4040
ArrayRemove,
4141
array_remove,
4242
array element,
43-
"removes the first element from the array equal to the given value.",
43+
"removes the first element from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
4444
array_remove_udf
4545
);
4646

4747
#[user_doc(
4848
doc_section(label = "Array Functions"),
49-
description = "Removes the first element from the array equal to the given value.",
49+
description = "Removes the first element from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
5050
syntax_example = "array_remove(array, element)",
5151
sql_example = r#"```sql
5252
> select array_remove([1, 2, 2, 3, 2, 1, 4], 2);
@@ -55,6 +55,13 @@ make_udf_expr_and_func!(
5555
+----------------------------------------------+
5656
| [1, 2, 3, 2, 1, 4] |
5757
+----------------------------------------------+
58+
59+
> select array_remove([1, 2, NULL, 2, 4], 2);
60+
+---------------------------------------------------+
61+
| array_remove(List([1,2,NULL,2,4]),Int64(2)) |
62+
+---------------------------------------------------+
63+
| [1, NULL, 2, 4] |
64+
+---------------------------------------------------+
5865
```"#,
5966
argument(
6067
name = "array",
@@ -127,21 +134,28 @@ make_udf_expr_and_func!(
127134
ArrayRemoveN,
128135
array_remove_n,
129136
array element max,
130-
"removes the first `max` elements from the array equal to the given value.",
137+
"removes the first `max` elements from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
131138
array_remove_n_udf
132139
);
133140

134141
#[user_doc(
135142
doc_section(label = "Array Functions"),
136-
description = "Removes the first `max` elements from the array equal to the given value.",
137-
syntax_example = "array_remove_n(array, element, max))",
143+
description = "Removes the first `max` elements from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
144+
syntax_example = "array_remove_n(array, element, max)",
138145
sql_example = r#"```sql
139146
> select array_remove_n([1, 2, 2, 3, 2, 1, 4], 2, 2);
140147
+---------------------------------------------------------+
141148
| array_remove_n(List([1,2,2,3,2,1,4]),Int64(2),Int64(2)) |
142149
+---------------------------------------------------------+
143150
| [1, 3, 2, 1, 4] |
144151
+---------------------------------------------------------+
152+
153+
> select array_remove_n([1, 2, NULL, 2, 4], 2, 2);
154+
+----------------------------------------------------------+
155+
| array_remove_n(List([1,2,NULL,2,4]),Int64(2),Int64(2)) |
156+
+----------------------------------------------------------+
157+
| [1, NULL, 4] |
158+
+----------------------------------------------------------+
145159
```"#,
146160
argument(
147161
name = "array",
@@ -219,13 +233,13 @@ make_udf_expr_and_func!(
219233
ArrayRemoveAll,
220234
array_remove_all,
221235
array element,
222-
"removes all elements from the array equal to the given value.",
236+
"removes all elements from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
223237
array_remove_all_udf
224238
);
225239

226240
#[user_doc(
227241
doc_section(label = "Array Functions"),
228-
description = "Removes all elements from the array equal to the given value.",
242+
description = "Removes all elements from the array equal to the given value. NULL elements already in the array are preserved when removing a non-NULL value. If `element` evaluates to NULL, the result is NULL rather than removing NULL entries.",
229243
syntax_example = "array_remove_all(array, element)",
230244
sql_example = r#"```sql
231245
> select array_remove_all([1, 2, 2, 3, 2, 1, 4], 2);
@@ -234,6 +248,13 @@ make_udf_expr_and_func!(
234248
+--------------------------------------------------+
235249
| [1, 3, 1, 4] |
236250
+--------------------------------------------------+
251+
252+
> select array_remove_all([1, 2, NULL, 2, 4], 2);
253+
+-----------------------------------------------------+
254+
| array_remove_all(List([1,2,NULL,2,4]),Int64(2)) |
255+
+-----------------------------------------------------+
256+
| [1, NULL, 4] |
257+
+-----------------------------------------------------+
237258
```"#,
238259
argument(
239260
name = "array",

0 commit comments

Comments
 (0)