You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "raushanprabhakar1 (via GitHub)" <gi...@apache.org> on 2026/05/16 20:04:38 UTC
[PR] fixing array length for empty array [datafusion]
raushanprabhakar1 opened a new pull request, #22279:
URL: https://github.com/apache/datafusion/pull/22279
## Which issue does this PR close?
- Closes #22264.
## Rationale for this change
PostgreSQL returns **NULL** for `array_length` on an empty dimension (e.g. `array_length(array[]::int[], 1)`). DataFusion returned **0**. This aligns semantics with PostgreSQL as requested in the issue.
## What changes are included in this PR?
- `array_length` / `list_length`: return SQL **NULL** when the evaluated dimension slice is empty, instead of `0`.
- Update `array/array_length.slt` expectations for empty arrays and add `array_length(ARRAY[]::INT[], 1)`.
## Are these changes tested?
Yes. `cargo test --profile=ci --test sqllogictests -- array/array_length`.
## Are there any user-facing changes?
Yes — observable SQL behavior: empty dimensions now yield **NULL** instead of **`0`** for `array_length` / `list_length`. Queries that depended on **`0`** may need **`IS NULL`** or **`COALESCE`**.
--
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] fixing array length for empty array [datafusion]
Posted by "raushanprabhakar1 (via GitHub)" <gi...@apache.org>.
raushanprabhakar1 commented on code in PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#discussion_r3257313933
##########
datafusion/sqllogictest/test_files/array/array_length.slt:
##########
Review Comment:
Hi @kumarUjjawal , Thanks for the review, added the tests as suggested by you. Thanks
--
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] fixing array length for empty array [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#issuecomment-4514872544
Thank you for working on this @raushanprabhakar1 We are having a discussion whether we want to force changes just to make datafusion follow one engine vs the other, in this case DuckDB has the same behaviour as datafusion so I don't see the need to change this at the moment. See https://github.com/apache/datafusion/issues/22264#issuecomment-4475490798
--
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] fixing array length for empty array [datafusion]
Posted by "kumarUjjawal (via GitHub)" <gi...@apache.org>.
kumarUjjawal commented on code in PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#discussion_r3256708000
##########
datafusion/sqllogictest/test_files/array/array_length.slt:
##########
Review Comment:
Let's add more tests:
```
# array_length scalar function #5b LargeList empty dimension
query II
select array_length(arrow_cast(make_array(), 'LargeList(Int64)')),
array_length(arrow_cast(make_array(), 'LargeList(Int64)'), 1)
----
NULL NULL
# array_length scalar function #5c empty inner dimension (was 0, now NULL)
query II
select array_length(make_array(make_array()), 2),
array_length(make_array(make_array(make_array())), 3)
----
NULL NULL
# list_length alias empty dimension
query II
select list_length(make_array()), list_length(make_array(), 1)
----
NULL NULL
# array_length over a column with an empty-array row
query ?II
select arr, array_length(arr), array_length(arr, 1)
from (values (make_array(1,2,3)),
(arrow_cast(make_array(), 'List(Int64)')),
(NULL::int[])) t(arr)
----
[1, 2, 3] 3 3
[] NULL NULL
NULL NULL NULL
```
--
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] fixing array length for empty array [datafusion]
Posted by "raushanprabhakar1 (via GitHub)" <gi...@apache.org>.
raushanprabhakar1 commented on code in PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#discussion_r3282729176
##########
datafusion/sqllogictest/test_files/array/array_length.slt:
##########
Review Comment:
Hi @kumarUjjawal , requesting you to review, Thanks
--
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] fixing array length for empty array [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#issuecomment-5041057807
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.
--
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] fixing array length for empty array [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #22279: fixing array length for empty array
URL: https://github.com/apache/datafusion/pull/22279
--
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] fixing array length for empty array [datafusion]
Posted by "raushanprabhakar1 (via GitHub)" <gi...@apache.org>.
raushanprabhakar1 commented on PR #22279:
URL: https://github.com/apache/datafusion/pull/22279#issuecomment-4467968004
Hi @Dandandan , requesting you to review. Thanks
--
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