apache / apache/datafusion

No way to get the schema for sliding accumulator state

Open
#14,701 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

The AggregateUDF trait includes a function `fn state_fields(&self, args: StateFieldsArgs) -> Result>` to get the types for the intermediate state of the aggregate. This is useful if we need to store the states, for example for multi-level aggregation.

For our use-case we also need to store the accumulator states as part of our checkpointing system. This works so long as we're using the standard accumulators, but breaks down if you want to use sliding accumulators. This is because some aggregates (for example, sum) have different state fields in sliding mode (for sum, this is additional "count" field, used to determine when we've retracted all of the data).

But there doesn't seem to be any way to determine what the state fields will be for a sliding accumulator. A couple of possible options here:

* Follow the pattern of is_distinct, which also can produce different accumulators. This is passed in to the state_fields function as a field on the StateFieldsArgs struct; we could add a similar one for is_sliding
* It seems like state_fields is really a property of the accumulator, not of the aggregate (as various aggregates may produce different accumulators depending on the options and which accumulator function is called), so it might be better to have the state_fields function on the accumulator instead of the aggregate.

We've gone ahead and implemented the first approach in our fork, but would be nice to get something in upstream that addresses this.

Contributor guide

Open the contributing guide

Research direction

Start by reading the AggregateUDF::state_fields function and StateFieldsArgs, then compare the state fields produced for standard and sliding accumulators such as sum. Done means the upstream API can expose the correct sliding-accumulator state schema for checkpointing, with coverage for the relevant behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
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.