Skip to content

fix: make array null argument handling follow SQL semantics#22508

Open
kumarUjjawal wants to merge 3 commits into
apache:mainfrom
kumarUjjawal:fix/null-handling-array
Open

fix: make array null argument handling follow SQL semantics#22508
kumarUjjawal wants to merge 3 commits into
apache:mainfrom
kumarUjjawal:fix/null-handling-array

Conversation

@kumarUjjawal
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Some array functions were not handling null index or count arguments correctly.

A null size or max value was sometimes treated like 0, which gave wrong results like [] or the original array. array_element also depended on Arrow buffer values in null slots.

This change makes these functions follow normal SQL null rules.

What changes are included in this PR?

  • Make array_resize return NULL when size is NULL
  • Make array_replace_n return NULL when max is NULL
  • Make array_remove_n return NULL when max is NULL
  • Make array_element check for null indexes explicitly
  • Clean up array_repeat so null counts stay explicit in offset building
  • Update array_remove_n field nullability so planner metadata matches runtime behavior
  • Add regression tests for these cases
  • Update SQL logic test outputs for the changed null behavior

Are these changes tested?

Yes.

I added regression tests for the changed Rust paths and updated the SQL logic tests.

Are there any user-facing changes?

These functions now return NULL for null index or count arguments instead of returning [], an unchanged array, or relying on accidental behavior.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 25, 2026
@kumarUjjawal kumarUjjawal force-pushed the fix/null-handling-array branch from b859522 to a07ec99 Compare May 25, 2026 12:21
@kumarUjjawal
Copy link
Copy Markdown
Contributor Author

@neilconway Could you take a look.

Copy link
Copy Markdown
Contributor

@neilconway neilconway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an SLT test for the array_element change, I think?

Otherwise, lgtm! Nice work.

Comment on lines +213 to +215
let array_field = args.arg_fields[0].as_ref().clone();
let nullable = args.arg_fields.iter().any(|f| f.is_nullable());
Ok(Arc::new(array_field.with_nullable(nullable)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we want the same change to return_field_from_args for array_remove and array_remove_all? Looking around, it seems like array_any_match has a similar bug. Can you fix these, either as part of this PR or in a separate PR?

Comment on lines +524 to +525
for element_nullability in [true, false] {
for count_nullability in [true, false] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could potentially clean up the deep nesting with iproduct!:

    for (array_nullable, item_nullable, element_nullable, count_nullable) in
        iproduct!(bools, bools, bools, bools)

But feel free to ignore if you think that's too clever.

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.

array functions (remove, resize, extract, replace, repeat) not properly handling nulls for index arguments

2 participants