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: [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]

Reply via email to