Skip to content

Ensure null inputs to array setop functions return null output#19683

Merged
alamb merged 4 commits intoapache:mainfrom
Jefffrey:array-setops-nulls
Jan 16, 2026
Merged

Ensure null inputs to array setop functions return null output#19683
alamb merged 4 commits intoapache:mainfrom
Jefffrey:array-setops-nulls

Conversation

@Jefffrey
Copy link
Copy Markdown
Contributor

@Jefffrey Jefffrey commented Jan 7, 2026

Which issue does this PR close?

Rationale for this change

Explained in issue.

What changes are included in this PR?

Change array_except, array_intersect and array_union UDFs to return null if either input is null.

Are these changes tested?

Added & fixed tests.

Are there any user-facing changes?

Behaviour change to a function output.

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Jan 7, 2026
Comment on lines -371 to +372
let l_values = if let Some(first_arr) = first_arr {
converter.convert_columns(&[first_arr])?
} else {
ele_should_be_null = true;
converter.empty_rows(0, 0)
};

let r_values = if let Some(second_arr) = second_arr {
converter.convert_columns(&[second_arr])?
} else {
ele_should_be_null = true;
converter.empty_rows(0, 0)
let (l_values, r_values) = match (l_arr, r_arr) {
(Some(l_arr), Some(r_arr)) => (
converter.convert_columns(&[l_arr])?,
converter.convert_columns(&[r_arr])?,
),
_ => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Little drive-by refactor here to skip the set logic below for nulls

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jan 7, 2026
@Jefffrey Jefffrey marked this pull request as ready for review January 7, 2026 14:23
Copy link
Copy Markdown
Contributor

@kosiew kosiew left a comment

Choose a reason for hiding this comment

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

LGTM

continue;
}

for i in r_start.as_usize()..r_end.as_usize() {
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.

Did you intentionally want to shadow i which is used in the outer for loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This wasn't intentional, refactored the names to clear things up 👍

@alamb alamb added this pull request to the merge queue Jan 16, 2026
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Jan 16, 2026

woohoo -- let's keep the code flowing

Merged via the queue into apache:main with commit ac67ae4 Jan 16, 2026
29 checks passed
@Jefffrey Jefffrey deleted the array-setops-nulls branch January 16, 2026 13:08
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
…e#19683)

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

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

Explained in issue.

## 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 array_except, array_intersect and array_union UDFs to return null
if either input is null.

## 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 & fixed 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.
-->

Behaviour change to a function output.

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array setops (union, intersect, except) should return null if either input is null

3 participants