apache / apache/beam

StateSpecs.combiningValue interface is very awkward to use

Open
#18,187 0 comments 0 reactions 0 assignees View on GitHub
bug core java P3
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

Using StateSpecs.combiningValue with built in combiners is very verbose. For example, to keep a running sum of ints:

```

@StateId("count")
private final StateSpec>
countSpec =
StateSpecs.combiningValue(
Sum.ofIntegers().getAccumulatorCoder(pipeline.getCoderRegistry(),
VarIntCoder.of()), Sum.ofIntegers());

```

This involves getting a reference to the pipeline into the DoFn, guessing/finding the proper type parameters for Sum.ofIntegers(), and manually pulling the accumulator coder out.

For combiners like Sum.ofIntegers() that have a fixed accumulator, the combiningValue call should be able to deduce that. Additionally, it would be nice to remove the type of the accumulator from the StateSpec object, since the user only needs the input and output types in their code.

Imported from Jira [BEAM-1276](https://issues.apache.org/jira/browse/BEAM-1276). Original Jira may contain additional context.
Reported by: millsd@google.com.

Contributor guide

Open the contributing guide

Research direction

Start by locating StateSpecs.combiningValue and the built-in Sum.ofIntegers() combiner in the Java SDK. Review how the current accumulator coder and StateSpec type parameters are supplied, then determine the API changes needed for fixed-accumulator combiners and input/output-only state types. Done means the verbose example can use the simplified interface without manually retrieving the accumulator coder.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data-engineering
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.