Skip to content

fix: maintain inner list nullability for array_sort#19948

Merged
comphead merged 2 commits intoapache:mainfrom
Jefffrey:fix-array-sort-inner-nullability
Jan 25, 2026
Merged

fix: maintain inner list nullability for array_sort#19948
comphead merged 2 commits intoapache:mainfrom
Jefffrey:fix-array-sort-inner-nullability

Conversation

@Jefffrey
Copy link
Contributor

@Jefffrey Jefffrey commented Jan 23, 2026

Which issue does this PR close?

Rationale for this change

#17657 introduced a regression since it cloned the inner field in the execution path but in the return_type function it still set nullability to true. Fix to ensure we maintain the field of the inner field as is.

What changes are included in this PR?

Change return_type to just pass through the input datatype as is.

Also refactor away usage of a null buffer builder in favour of copying the input array null buffer.

Are these changes tested?

Added tests.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jan 23, 2026
@Jefffrey Jefffrey requested a review from timsaucer January 23, 2026 04:13
Comment on lines -145 to -147
arg_type => {
plan_err!("{} does not support type {arg_type}", self.name())
}
Copy link
Member

Choose a reason for hiding this comment

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

By removing this, don't we delay the error generated when someone passes an invalid type until execution? It seems like we want this check to still happen during planning.

Maybe something like match on DataType::Null | DataType::List(_) | ataType::LargeList(_) => Ok(arg_types[0].clone())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The signature should already guard us from that path; it was only there for completeness before. Worst case if something does go wrong at least we'll just error normally at execution time instead of panicking via unreachable!() for example

@comphead comphead added this pull request to the merge queue Jan 25, 2026
Merged via the queue into apache:main with commit 8023947 Jan 25, 2026
29 checks passed
@Jefffrey Jefffrey deleted the fix-array-sort-inner-nullability branch January 26, 2026 03:09
alamb pushed a commit to alamb/datafusion that referenced this pull request Mar 11, 2026
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Closes apache#19947

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

apache#17657 introduced a regression since it cloned the inner field in the
execution path but in the `return_type` function it still set
nullability to true. Fix to ensure we maintain the field of the inner
field as is.

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

Change `return_type` to just pass through the input datatype as is.

Also refactor away usage of a null buffer builder in favour of copying
the input array null buffer.

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

Added tests.

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

No.

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
alamb added a commit that referenced this pull request Mar 12, 2026
- Part of #20855
- Closes #19947 on branch-52

This PR:
- Backports #19948 from
@Jefffrey to the branch-52 line

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
lukekim pushed a commit to spiceai/datafusion that referenced this pull request Mar 12, 2026
…pache#20878)

- Part of apache#20855
- Closes apache#19947 on branch-52

This PR:
- Backports apache#19948 from
@Jefffrey to the branch-52 line

Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: array_sort fails on list with inner non-nullable field

3 participants