Skip to content

fixing array length for empty array#22279

Open
raushanprabhakar1 wants to merge 1 commit into
apache:mainfrom
raushanprabhakar1:fix/empty-array-lenght
Open

fixing array length for empty array#22279
raushanprabhakar1 wants to merge 1 commit into
apache:mainfrom
raushanprabhakar1:fix/empty-array-lenght

Conversation

@raushanprabhakar1
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

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.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 2026
@raushanprabhakar1
Copy link
Copy Markdown
Contributor Author

Hi @Dandandan , requesting you to review. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: array_length of an empty array dimension should be NULL

1 participant