feat(spark): add arrays_overlap with Spark three-valued null semantics#20781
Draft
n0r0shi wants to merge 1 commit intoapache:mainfrom
Draft
feat(spark): add arrays_overlap with Spark three-valued null semantics#20781n0r0shi wants to merge 1 commit intoapache:mainfrom
arrays_overlap with Spark three-valued null semantics#20781n0r0shi wants to merge 1 commit intoapache:mainfrom
Conversation
DataFusion's built-in `array_has_any` returns `false` when arrays have no definite overlap but contain null elements. Spark's `arrays_overlap` returns `null` in this case (three-valued logic: overlap is unknown because nulls could match any value). This wraps `array_has_any` and patches results where `false` + either array has nulls → `null`, following the same pattern as SparkArrayContains.
Contributor
|
it might be similar to #20611 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #15914 (partial — adds one more Spark-compatible function)
Related: apache/datafusion-comet#3645
Rationale
Spark's
arrays_overlapuses three-valued null logic, which differs from DataFusion's built-inarray_has_any:arrays_overlaparray_has_any[1, 2],[2, 3]truetrue[1, 2],[3, 4]falsefalse[1, NULL],[3]nullfalse[1, 2],[3, NULL]nullfalse[1, NULL],[1, 3]truetrueIn Spark, when there's no definite overlap but either array contains a null element, the result is
null.What changes are included in this PR?
Adds
SparkArraysOverlapto thedatafusion-sparkcrate, following the same pattern asSparkArrayContains: delegate to DataFusion'sarray_has_any, then patch rows where the result isfalseand either input array contains null elements tonull.Are these changes tested?
Unit tests covering:
truefalsenullnulltrue(definite match trumps null)null