[ 
https://issues.apache.org/jira/browse/BEAM-7567?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17122779#comment-17122779
 ] 

Beam JIRA Bot commented on BEAM-7567:
-------------------------------------

This issue is P2 but has been unassigned without any comment for 60 days so it 
has been labeled "stale-P2". If this issue is still affecting you, we care! 
Please comment and remove the label. Otherwise, in 14 days the issue will be 
moved to P3.

Please see https://beam.apache.org/contribute/jira-priorities/ for a detailed 
explanation of what these priorities mean.


> StateSpec should contain the state id
> -------------------------------------
>
>                 Key: BEAM-7567
>                 URL: https://issues.apache.org/jira/browse/BEAM-7567
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Luke Cwik
>            Priority: P2
>              Labels: backwards-incompatible, stale-P2
>             Fix For: 3.0.0
>
>
> In the Java SDK we currently ask users to define a state spec as:
> {code:java}
> new DoFn<KV<MyKey, MyValue>, KV<Integer, KV<MyKey, MyValue>>>() {
>   // A state cell holding a single Integer per key+window
>   @StateId("index")
>   private final StateSpec<ValueState<Integer>> indexSpec =
>       StateSpecs.value(VarIntCoder.of());
>   @ProcessElement
>   public void processElement(
>       ProcessContext context,
>       @StateId("index") ValueState<Integer> index) {
>     int current = firstNonNull(index.read(), 0);
>     context.output(KV.of(current, context.element()));
>     index.write(current+1);
>   }
> }
> {code}
> The suggestion is to move the @StateId into the StateSpec so the could would 
> look like:
> {code:java}
> new DoFn<KV<MyKey, MyValue>, KV<Integer, KV<MyKey, MyValue>>>() {
>   // A state cell holding a single Integer per key+window
>   private final StateSpec<ValueState<Integer>> indexSpec =
>       StateSpecs.value("index", VarIntCoder.of());
>   @ProcessElement
>   public void processElement(
>       ProcessContext context,
>       @StateId("index") ValueState<Integer> index) {
>     int current = firstNonNull(index.read(), 0);
>     context.output(KV.of(current, context.element()));
>     index.write(current+1);
>   }
> }
> {code}
> We should also remove the coder from the StateSpec hashCode and equals method.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to