xiedeyantu opened a new pull request, #22302:
URL: https://github.com/apache/datafusion/pull/22302

   ## Which issue does this PR close?
   
   - Closes #22254 
   
   ## Rationale for this change
   
   PostgreSQL treats negative array subscripts as out of bounds and returns 
`NULL`. DataFusion was incorrectly interpreting negative subscripts as indexing 
from the end of the array, which caused behavioral mismatch.
   
   ## What changes are included in this PR?
   
   - Updated `array_element` / array subscript evaluation to treat non-positive 
indexes as out of bounds and return `NULL`.
   - Updated sqllogictest coverage for array subscript and `array_element` 
behavior, including the `[-1]` case.
   
   ## Are these changes tested?
   
   Yes.
   
   Validated with:
   - `cargo test -p datafusion-functions-nested 
test_array_element_non_positive_indexes_return_null`
   - `cargo test -p datafusion-sqllogictest --test sqllogictests array_index`
   - `cargo test -p datafusion-sqllogictest --test sqllogictests expr`
   
   ## Are there any user-facing changes?
   
   Yes. Array subscripts with negative indexes now return `NULL` instead of 
indexing from the end, aligning DataFusion behavior with PostgreSQL.
   


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