Skip to content

feat: filter and take for dictionary arrays - #716

Merged
zeroshade merged 3 commits into
apache:mainfrom
lesam:lesam/add-filter-take-dictionary
Jun 5, 2026
Merged

zeroshade merged 3 commits into
apache:mainfrom
lesam:lesam/add-filter-take-dictionary

Conversation

@lesam

@lesam lesam commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Add 'take' and 'filter' implementations for dictionary arrays. These implementations simply filter/take on the index column and shallow-copy the dictionary.

#714

Rationale for this change

It would be nice for 'take' and 'filter' to work for all array encodings, including dictionary

What changes are included in this PR?

Just 'take' and 'filter' implementations and an addition to the tests

Are these changes tested?

Unit tests added

Are there any user-facing changes?

These will now work instead of failing with an error like:

not implemented: function 'array_filter' has no kernel matching input types (dictionary<values=utf8, indices=int8, ordered=false>, bool)

@lesam
lesam force-pushed the lesam/add-filter-take-dictionary branch from db89029 to b8abbec Compare March 16, 2026 18:46
@zeroshade

Copy link
Copy Markdown
Member

@lesam is this still a draft? Or is it ready for review?

@lesam
lesam force-pushed the lesam/add-filter-take-dictionary branch from b8abbec to 512d8d0 Compare June 2, 2026 16:40
@lesam
lesam marked this pull request as ready for review June 2, 2026 16:40
@lesam
lesam requested a review from zeroshade as a code owner June 2, 2026 16:40
@lesam

lesam commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@zeroshade I've updated the PR with some comments, it's ready for review.

Add 'take' and 'filter' implementations for dictionary arrays. These
implementations simply filter/take on the index column and shallow-copy
the dictionary.
@lesam
lesam force-pushed the lesam/add-filter-take-dictionary branch from 512d8d0 to 555fb02 Compare June 2, 2026 16:50

@zeroshade zeroshade 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.

LGTM! Very nice, just a couple nitpicks so let me know what you think.

Also, can we just add a single line documentation note explaining that the dictionary itself isn't compacted or modified? i.e. after execution of the filter, the dictionary itself would still contain all the same values. This is intentional, but might be non-obvious.

for _, dt := range baseBinaryTypes {
suite.Run(t, &FilterKernelWithString{dt: dt})
}
suite.Run(t, &FilterKernelWithString{dt: &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8, ValueType: arrow.BinaryTypes.String}})

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.

Can we add tests for a few more combinations of different index/value types? Perhaps add a numeric dict test or a complex type like list/struct? Just to add more type coverage to the tests for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a commit with more tests

Comment thread arrow/compute/selection.go Resolved
@lesam
lesam force-pushed the lesam/add-filter-take-dictionary branch from 0187fe1 to 6c6ece4 Compare June 4, 2026 14:39
@lesam

lesam commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Also, can we just add a single line documentation note explaining that the dictionary itself isn't compacted or modified? i.e. after execution of the filter, the dictionary itself would still contain all the same values. This is intentional, but might be non-obvious.

I've added this on dictionaryTake and dictionaryFilter - did you want it on the public generic Take / Filter doc comment as well? My feeling is not to add it to the public method contract, to give more flexibility to change it in the future.

@lesam
lesam force-pushed the lesam/add-filter-take-dictionary branch from 6c6ece4 to 390e769 Compare June 4, 2026 14:42
@lesam
lesam requested a review from zeroshade June 4, 2026 17:27

@zeroshade zeroshade 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.

LGTM. Will merge once CI finishes

@zeroshade
zeroshade merged commit bbc81ce into apache:main Jun 5, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants