You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Jefffrey (via GitHub)" <gi...@apache.org> on 2026/04/22 18:01:44 UTC

[I] `array_position` doesn't check nulls in array index & fails to handle nulls properly [datafusion]

Jefffrey opened a new issue, #21792:
URL: https://github.com/apache/datafusion/issues/21792

   ### Describe the bug
   
   Test cases:
   
   ```sql
   select array_position(haystack, needle, index_from)
   from values
     ([1, 2], 1, 2),
     ([1, 2], 1, null)
   t(haystack, needle, index_from)
   ```
   
   - Currently this fails because `0` is out of bounds, but this is only because by default the value underneath a null is usually 0; we can construct an array where this isn't the case and pass in a valid in-bounds value even if it should be masked by a null
   - This should instead fail by checking nulls, as scalar path also raises exec error if it detects a null for the index argument
   
   ```sql
   > select array_position(haystack, needle), array_positions(haystack, needle)
   from values
     ([[1], null], null),
     ([[]], null)
   t(haystack, needle);
   +-------------------------------------+--------------------------------------+
   | array_position(t.haystack,t.needle) | array_positions(t.haystack,t.needle) |
   +-------------------------------------+--------------------------------------+
   | NULL                                | []                                   |
   | 1                                   | [1]                                  |
   +-------------------------------------+--------------------------------------+
   ```
   
   - This should return `2 | [2]` for the first row and `NULL | []` for the second row
   - This is because in the first row, we can find a null element so we return that position
   - And for the second row we can't find any null, so we shouldn't return a position
   
   ### To Reproduce
   
   _No response_
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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.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: [I] `array_position` doesn't check nulls in array index & fails to handle nulls properly [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on issue #21792:
URL: https://github.com/apache/datafusion/issues/21792#issuecomment-4298776524

   Related: https://github.com/apache/datafusion/issues/6808


-- 
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