Skip to content

Support equality/inequality and NULL comparisons for ARRAYs#4080

Merged
RobertBrunel merged 1 commit intoFoundationDB:mainfrom
RobertBrunel:empty-array
Apr 17, 2026
Merged

Support equality/inequality and NULL comparisons for ARRAYs#4080
RobertBrunel merged 1 commit intoFoundationDB:mainfrom
RobertBrunel:empty-array

Conversation

@RobertBrunel
Copy link
Copy Markdown
Contributor

@RobertBrunel RobertBrunel commented Apr 14, 2026

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.

@RobertBrunel RobertBrunel self-assigned this Apr 14, 2026
@RobertBrunel RobertBrunel added the enhancement New feature or request label Apr 14, 2026
Comment thread yaml-tests/src/test/resources/arrays-operators.yamsql
@RobertBrunel RobertBrunel force-pushed the empty-array branch 2 times, most recently from c791a31 to 271704d Compare April 17, 2026 14:19
@RobertBrunel RobertBrunel requested a review from hatyo April 17, 2026 14:23
Copy link
Copy Markdown
Contributor

@hatyo hatyo left a comment

Choose a reason for hiding this comment

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

LGTM

@RobertBrunel RobertBrunel force-pushed the empty-array branch 2 times, most recently from 78fc82c to 1cf398f Compare April 17, 2026 14:58
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`.
@RobertBrunel RobertBrunel merged commit f6c96b8 into FoundationDB:main Apr 17, 2026
13 checks passed
@RobertBrunel RobertBrunel deleted the empty-array branch April 17, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants