You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "dd-david-levin (via GitHub)" <gi...@apache.org> on 2026/03/22 22:05:06 UTC
[PR] fix: string_to_array('', delim) returns empty array for PostgreSQL compatibility [datafusion]
dd-david-levin opened a new pull request, #21104:
URL: https://github.com/apache/datafusion/pull/21104
## Problem
`string_to_array('', ',')` was returning `['']` (an array containing one empty string) instead of `[]` (an empty array), which is incorrect according to PostgreSQL behavior.
**Root cause:** Rust's `str::split()` on an empty string always yields one empty-string element. So `"".split(",")` produces `[""]`, which was being appended to the list builder as-is.
**PostgreSQL expected behavior** (see [db-fiddle](https://www.db-fiddle.com/f/oCF8EPaZFkDNKSg28rVVWy/0)):
```sql
SELECT string_to_array('', ',');
-- {} (empty array)
```
## Fix
Added an `is_empty()` guard in `string_to_array_impl` in `datafusion/functions-nested/src/string.rs`. When the input string is empty and the delimiter is a non-empty string, we now append an empty list instead of splitting. The fix applies to both the plain variant and the `null_value` variant of the function.
## Test
Added a sqllogictest case in `datafusion/sqllogictest/test_files/array.slt`:
```sql
SELECT string_to_array('', ',')
----
[]
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: string_to_array('', delim) returns empty array for PostgreSQL compatibility [datafusion]
Posted by "gabotechs (via GitHub)" <gi...@apache.org>.
gabotechs commented on PR #21104:
URL: https://github.com/apache/datafusion/pull/21104#issuecomment-4112333282
Looks good. Thanks @dd-david-levin for the PR and @LiaCastaneda for the review! I'll leave this here until tomorrow in case someone else wants to chime in.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: string_to_array('', delim) returns empty array for PostgreSQL compatibility [datafusion]
Posted by "gabotechs (via GitHub)" <gi...@apache.org>.
gabotechs merged PR #21104:
URL: https://github.com/apache/datafusion/pull/21104
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org