Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/10224#discussion_r47173853
--- Diff:
streaming/src/main/scala/org/apache/spark/streaming/StateSpec.scala ---
@@ -37,50 +37,64 @@ import org.apache.spark.{HashPartitioner, Partitioner}
*
* Example in Scala:
* {{{
- * def trackingFunction(data: Option[ValueType], wrappedState:
State[StateType]): EmittedType = {
- * ...
+ * // A mapping function that maintains an integer state and return a
String
+ * def mappingFunction(key: String, value: Option[Int], state:
State[Int]): Option[String] = {
+ * // Use state.exists(), state.get(), state.update() and
state.remove()
+ * // to manage state, and return the necessary string
* }
*
- * val spec = StateSpec.function(trackingFunction).numPartitions(10)
+ * val spec = StateSpec.function(mappingFunction).numPartitions(10)
*
- * val emittedRecordDStream =
keyValueDStream.trackStateByKey[StateType, EmittedDataType](spec)
+ * val mapWithStateDStream = keyValueDStream.mapWithState[StateType,
MappedType](spec)
* }}}
*
* Example in Java:
* {{{
- * StateSpec<KeyType, ValueType, StateType, EmittedDataType> spec =
- * StateSpec.<KeyType, ValueType, StateType,
EmittedDataType>function(trackingFunction)
- * .numPartition(10);
+ * // A mapping function that maintains an integer state and return a
string
+ * Function3<String, Optional<Integer>, State<Integer>, String>
mappingFunction =
+ * new Function3<String, Optional<Integer>, State<Integer>,
String>() {
+ * @Override
+ * public Optional<String> call(Optional<Integer> value,
State<Integer> state) {
+ * // Use state.exists(), state.get(), state.update() and
state.remove()
+ * // to manage state, and return the necessary string
+ * }
+ * };
*
- * JavaTrackStateDStream<KeyType, ValueType, StateType, EmittedType>
emittedRecordDStream =
- * javaPairDStream.<StateType, EmittedDataType>trackStateByKey(spec);
+ * JavaMapWithStateDStream<Integer, Integer, Integer, String>
mapWithStateDStream =
--- End diff --
nit: the key type is `String`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]