You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/03 16:29:31 UTC

[GitHub] [beam] kennknowles opened a new issue, #18174: ValueState could use an initial/default value

kennknowles opened a new issue, #18174:
URL: https://github.com/apache/beam/issues/18174

   In writing example state code with `ValueState` there is almost always a use of `firstNonNull(state.read(), defaultValue)`. It would be nice to bake this into the declaration.
   
   Imported from Jira [BEAM-1335](https://issues.apache.org/jira/browse/BEAM-1335). Original Jira may contain additional context.
   Reported by: kenn.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] ritikBhandari commented on issue #18174: ValueState could use an initial/default value

Posted by GitBox <gi...@apache.org>.
ritikBhandari commented on issue #18174:
URL: https://github.com/apache/beam/issues/18174#issuecomment-1146166677

   what is meant by 'declaration' in this context?  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kennknowles commented on issue #18174: ValueState could use an initial/default value

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on issue #18174:
URL: https://github.com/apache/beam/issues/18174#issuecomment-1448651820

   I like number 2. I don't know if there are any pitfalls, but it makes sense to me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] HoussemNasri commented on issue #18174: ValueState could use an initial/default value

Posted by "HoussemNasri (via GitHub)" <gi...@apache.org>.
HoussemNasri commented on issue #18174:
URL: https://github.com/apache/beam/issues/18174#issuecomment-1436042192

   I have looked into this issue and I have two possible solutions in mind:
   1. **Return an optional from read.**
    Since the read method is expected to return a `null` value sometimes – as stated in the comment above it, I figured it's appropriate to wrap its return value in an optional. Then, clients can use the `orElse` method of the Optional type to select a default value. I couldn't find any implementation of the `ValueState` interface so I'm unsure of the feasibility of this solution. However, I think it's worth considering.
   2. **Create an overloaded method of `read` that takes the default value as a parameter**
   Since beam can run on Java 8, we can create a default method `read(T defaultValue)` in the `ValueState` interface that returns the default value if `read()` returns `null`.
   
   Personally, I'm in favor of the latter solution, as it requires fewer changes to the code. And it's optional to use compared to the former solution where every class that uses the `read()` method needs to be changed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org