Initial implementation of `variant_array_length` processing function by sebastiaan-dev · Pull Request #23167 · duckdb/duckdb · GitHub
Skip to content

Initial implementation of variant_array_length processing function - #23167

Merged
lnkuiper merged 7 commits into
duckdb:mainfrom
sebastiaan-dev:feat/fn-variant-array-length
Jun 11, 2026
Merged

lnkuiper merged 7 commits into
duckdb:mainfrom
sebastiaan-dev:feat/fn-variant-array-length

Conversation

@sebastiaan-dev

@sebastiaan-dev sebastiaan-dev commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

This PR resolves https://github.com/duckdblabs/duckdb-internal/issues/9463, introducing an initial implementation for variant_array_length. This function takes a VARIANT-type object as input and a path. It returns the number of elements in the array variant, or 0 if it is not an array. If path is specified, return the number of elements in the array at the given path. If path is of type VARCHAR[], the result will be a list of array lengths.

Examples

variant_array_length({'a': [1, 2]}::VARIANT, '')
> 0

variant_array_length({'a': [1, 2]}::VARIANT, 'a')
> 2

variant_array_length({'a': [1, 2]}::VARIANT, ['a', 'a'])
> [2, 2]

Interface

variant_array_length(variant[, path])

Parameters

  • variant is of type VARIANT
  • path is optional and of type VARCHAR or VARCHAR[]

Refactor

To reduce code duplication a VariantPathFunction struct was introduced which abstracts a part of the writing. As a consequence we have redundant FlatVector::Validity and FlatVector::GetData calls in the write_fn implementations. Reducing this is deferred as a later optional optimization. Due to having a generalized writing skeleton, it also resolves https://github.com/duckdblabs/duckdb-internal/issues/9459.

Follow-up work

The current implementation has several limitations, please see https://github.com/duckdblabs/duckdb-internal/issues/9125#issue-4375370873 for more information.

@github-actions github-actions Bot added the Member label Jun 9, 2026
@sebastiaan-dev sebastiaan-dev self-assigned this Jun 9, 2026
@sebastiaan-dev sebastiaan-dev added the Needs Documentation Use for issues or PRs that require changes in the documentation label Jun 9, 2026

@Tishj Tishj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great! The abstractions keep getting better and better 🚀

@lnkuiper

Copy link
Copy Markdown
Member

@lnkuiper
lnkuiper added this pull request to the merge queue Jun 11, 2026
Merged via the queue into duckdb:main with commit e855f1f Jun 11, 2026
54 checks passed
@sebastiaan-dev
sebastiaan-dev deleted the feat/fn-variant-array-length branch June 11, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Member Needs Documentation Use for issues or PRs that require changes in the documentation Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants