Support equality/inequality and NULL comparisons for ARRAYs#4080
Merged
RobertBrunel merged 1 commit intoFoundationDB:mainfrom Apr 17, 2026
Merged
Support equality/inequality and NULL comparisons for ARRAYs#4080RobertBrunel merged 1 commit intoFoundationDB:mainfrom
RobertBrunel merged 1 commit intoFoundationDB:mainfrom
Conversation
b58a0d2 to
fd09412
Compare
hatyo
reviewed
Apr 16, 2026
hatyo
reviewed
Apr 16, 2026
c791a31 to
271704d
Compare
78fc82c to
1cf398f
Compare
This change adds the usual binary equality and inequality predicates for ARRAY values, =, <>, and `IS [NOT] DISTINCT FROM`, and well as unary `IS NULL` and `IS NOT NULL` predicates. To smoothly support comparisons with the untyped empty array constructor (as in `… WHERE <array> = []`), we also add appropriate promotion logic. For completeness, further overloads are added to handle edge cases involving [] or NULL on both sides (as in `NULL = []` or `[] = []`). Specifically: * In `AbstractArrayConstructorValue`, allow the evaluation of []. This helps us avoid special logic in other places. Also fix the `with()` method so that it picks the correct element type. * In `EvaluateConstantPromotionRule`, handle the constant promotion case from [] to a typed array. * In `MessageHelpers` and `PromoteValue`, make sure the coercion logic for arrays can handle the "None" type smoothly. * In `RelOpValue`, add the relevant `UnaryPhysicalOperator` and `BinaryPhysicalOperator` variants. Also add logic in `evaluate()` to promote the arguments to their maximum type if arrays are involved. This way we don’t have to define a multitude of operator overloads for mixes of ARRAY and NONE/NULL arguments. * In `Type#maximumType()`, add the necessary logic for NONE. * Use the SQLSTATE code 42804 when comparison operands are incompatible. Out of scope: * Comparisons of different ARRAY types such as [1I] = [1L]. If the element types can be promoted (here from INT to LONG), this could be supported in the future. * Optimizing `= []` further by handling it with a dedicated predicate. * Constant folding for constant comparisons such as `[1] = []`. Testing: * New integration tests in `arrays-operators.yamsql`.
1cf398f to
83e9551
Compare
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.
This change adds the usual binary equality and inequality predicates for
ARRAY values, =, <>, and
IS [NOT] DISTINCT FROM, and well as unaryIS NULLandIS NOT NULLpredicates. To smoothly support comparisonswith the untyped empty array constructor (as in
… WHERE <array> = []),we also add appropriate promotion logic. For completeness, further
overloads are added to handle edge cases involving [] or NULL on both
sides (as in
NULL = []or[] = []).Specifically:
AbstractArrayConstructorValue, allow the evaluation of []. Thishelps us avoid special logic in other places. Also fix the
with()method so that it picks the correct element type.
EvaluateConstantPromotionRule, handle the constant promotion casefrom [] to a typed array.
MessageHelpersandPromoteValue, make sure the coercion logicfor arrays can handle the "None" type smoothly.
RelOpValue, add the relevantUnaryPhysicalOperatorandBinaryPhysicalOperatorvariants. Also add logic inevaluate()topromote the arguments to their maximum type if arrays are involved.
This way we don’t have to define a multitude of operator overloads for
mixes of ARRAY and NONE/NULL arguments.
Type#maximumType(), add the necessary logic for NONE.Out of scope:
element types can be promoted (here from INT to LONG), this could be
supported in the future.
= []further by handling it with a dedicated predicate.[1] = [].Testing:
arrays-operators.yamsql.