apache / apache/arrow

[Python] group_by functionality directly on large dataset, instead of on a table?

Open
#13,747 15 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 18h
Merged PRs (30d)
91

Description

I have a large dataset that I would like to use `group_by` on without having to read the entire table into memory first.

After reading the documentation it seems `dataset.to_batches` is the best way of doing this? But it gets really complex when using other aggregation methods than for example `count` and `sum`.

I implemented it like below for `count` and `sum`, but for other more complex aggregations I am still forced to read the entire table.

```python
table = []
for batch in ds.to_batches(columns=columns, filter=filters, batch_size=1e6):
t = pyarrow.Table.from_batches([batch])
table.append(t.group_by(group_by).aggregate(agg))
table = pyarrow.concat_tables(table)

# then after this I use group_by again on the concatenated table with `sum` as aggregation method
```

Thankful for any pointers or comments!

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the Python Dataset.to_batches and Table.group_by APIs, focusing on how aggregations are handled batch by batch. Define what a direct large-dataset group_by should support beyond count and sum, and consider how completion can avoid materializing the entire table in memory.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.