Skip to content

Support the CARDINALITY() SQL function#4074

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

Support the CARDINALITY() SQL function#4074
RobertBrunel merged 1 commit intoFoundationDB:mainfrom
RobertBrunel:cardinality-1

Conversation

@RobertBrunel
Copy link
Copy Markdown
Contributor

@RobertBrunel RobertBrunel commented Apr 10, 2026

Introduce a SQL function CARDINALITY() to return the number of elements in an array. The return type is INTEGER (not LONG), which is aligned with the type of array subscripts.

CARDINALITY() cannot yet be used in an index definition. Attempting to do so results in a RelationalException with the message "Unsupported index definition, not all fields can be mapped to key expression".

Testing:

  • Integration tests in arrays_cardinality.yamsql.
  • Unit tests in CardinalityValueTest.java.

@RobertBrunel RobertBrunel self-assigned this Apr 10, 2026
@RobertBrunel RobertBrunel added the enhancement New feature or request label Apr 10, 2026
@RobertBrunel RobertBrunel marked this pull request as draft April 10, 2026 10:59
@RobertBrunel RobertBrunel requested a review from normen662 April 10, 2026 10:59
Comment thread yaml-tests/src/test/resources/arrays_cardinality.yamsql
@RobertBrunel RobertBrunel marked this pull request as ready for review April 17, 2026 10:39
Copy link
Copy Markdown
Contributor

@pengpeng-lu pengpeng-lu left a comment

Choose a reason for hiding this comment

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

Please address the Teamscale warnings before merge, rest looks good to me!

Introduce a SQL function CARDINALITY() to return the number of elements
in an array. The return type is INTEGER (not LONG), which is aligned
with the type of array subscripts.

CARDINALITY() cannot yet be used in an index definition. Attempting to
do so results in a `RelationalException` with the message "Unsupported
index definition, not all fields can be mapped to key expression".

Testing:
* Integration tests in `arrays_cardinality.yamsql`.
* Unit tests in `CardinalityValueTest.java`.
@github-actions
Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 2
  • Dropped queries: 0
  • Plan changed + metrics changed: 0
  • Plan unchanged + metrics changed: 0
ℹ️ About this analysis

This automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:

  • New queries: Queries added in this PR
  • Dropped queries: Queries removed in this PR. These should be reviewed to ensure we are not losing coverage.
  • Plan changed + metrics changed: The query plan has changed along with planner metrics.
  • Metrics only changed: Same plan but different metrics

The last category in particular may indicate planner regressions that should be investigated.

New Queries

Count of new queries by file:

  • yaml-tests/src/test/resources/arrays_cardinality.metrics.yaml: 2

@RobertBrunel RobertBrunel merged commit 5ba253a into FoundationDB:main Apr 17, 2026
14 checks passed
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