Skip to content

Commit cfafce4

Browse files
authored
chore: add array_remove_* NULL handling changes to Upgrade Guide (#21769)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change Initially posted by @gabotechs in #21013 (comment) <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 9a1ed57 commit cfafce4

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

  • docs/source/library-user-guide/upgrading

docs/source/library-user-guide/upgrading/53.0.0.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,45 @@ Now:
507507
+-------+
508508
0 row(s) fetched.
509509
```
510+
511+
### `array_remove`, `array_remove_n`, `array_remove_all` now return NULL when the element argument is NULL
512+
513+
Previously, calling `array_remove(array, NULL)` would attempt to match and
514+
remove NULL entries from the array, returning the array with NULLs stripped.
515+
Now, passing NULL as the element to remove causes the function to return NULL,
516+
which is consistent with standard SQL NULL propagation semantics.
517+
518+
The same change applies to `array_remove_n` (aliases: `list_remove_n`) and
519+
`array_remove_all` (aliases: `list_remove_all`).
520+
521+
**Who is affected:**
522+
523+
- Queries that call `array_remove`, `array_remove_n`, or `array_remove_all`
524+
with a NULL element argument (literal or column-derived).
525+
526+
**Behavioral changes:**
527+
528+
| Expression | Old result | New result |
529+
| ---------------------------------------------------- | ----------------- | ---------- |
530+
| `array_remove(make_array(1, NULL, 2), NULL)` | `[1, 2]` | `NULL` |
531+
| `array_remove(make_array(1, NULL, 2, NULL), NULL)` | `[1, 2, NULL]` | `NULL` |
532+
| `array_remove_n(make_array(1, 2, 2, 1, 1), NULL, 2)` | `[1, 2, 2, 1, 1]` | `NULL` |
533+
| `array_remove_all(make_array(1, 2, 2, 1, 1), NULL)` | `[1, 2, 2, 1, 1]` | `NULL` |
534+
535+
**Migration guide:**
536+
537+
If your queries relied on the old behavior to strip NULLs from arrays, use
538+
`array_remove_all` with a non-NULL sentinel or use `array_filter` instead:
539+
540+
```sql
541+
-- Before (removed NULLs from array):
542+
SELECT array_remove(make_array(1, NULL, 2), NULL);
543+
-- Old result: [1, 2]
544+
545+
-- After (returns NULL due to NULL propagation):
546+
SELECT array_remove(make_array(1, NULL, 2), NULL);
547+
-- New result: NULL
548+
```
549+
550+
See [#21011](https://github.com/apache/datafusion/issues/21011) and
551+
[PR #21013](https://github.com/apache/datafusion/pull/21013) for details.

0 commit comments

Comments
 (0)