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

   ## Summary
   
   - Fix `array_length` / `list_length` so an empty list at the requested 
dimension returns SQL `NULL`, matching PostgreSQL behavior 
([apache/datafusion#22264](https://github.com/apache/datafusion/issues/22264)).
   - Preserve outer-array null rows when computing first-dimension lengths.
   
   ## Root cause
   
   `first_dimension_length` and `compute_array_length` always emitted `0` for 
zero-length dimensions. PostgreSQL returns `NULL` when the target dimension has 
no elements (for example `array_length(array[]::int[], 1)`).
   
   ## Solution
   
   - Introduce `nullable_dimension_length` that maps length `0` to `None`.
   - Apply it in first-dimension and nth-dimension paths.
   - Keep parent list nulls when building first-dimension results.
   
   ## Test plan
   
   - Updated `datafusion/sqllogictest/test_files/array/array_length.slt` (empty 
array + case #5 expectations).
   - Added unit regression `array_length_empty_list_is_null` in `length.rs`.
   - Local `cargo test -p datafusion-functions-nested --lib length::tests` was 
not run to completion: Docker Desktop engine was unavailable after a partial 
Linux build attempt.
   - CI: `cargo test -p datafusion-functions-nested --lib length::tests` and 
sqllogictest `array/array_length.slt`.
   
   Fixes #22264.


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