apache / apache/arrow

[C++] Add a "list_contains" kernel

Open
#33,295 8 comments 4 reactions 1 assignee Claimed by @alexshpilkin View on GitHub
Component: C++ Status: needs champion Type: enhancement
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 18h
Merged PRs (30d)
91

Description

Assume you have a list array:

```Java

arr = pa.array([["a", "b"], ["a", "c"], ["b", "c", "d"]])
```

And you want to know for each list if it contains a certain value (of the same type as the list's values). A "list_contains" function (or other name) would be useful for that:

```Java

pc.list_contains(arr, "a")
# -> True, True False
```

The current workaround that I found was flattening, checking equality, and then reducing again with groupby, but this is quite tedious:

```Java

>>> temp = pa.table({'index': pc.list_parent_indices(arr), 'contains_value': pc.equal(pc.list_flatten(arr), "a")})
>>> temp.group_by('index').aggregate([('contains_value', 'any')])['contains_value_any'].chunk(0)

[
true,
true,
false
]
```

But this also only works if there are no empty or missing list values.

**Reporter**: [Joris Van den Bossche](https://issues.apache.org/jira/browse/ARROW-18097) / @jorisvandenbossche
#### Related issues:
- https://github.com/apache/arrow/issues/32045 (duplicates)

**Note**: *This issue was originally created as [ARROW-18097](https://issues.apache.org/jira/browse/ARROW-18097). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.