Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10224#discussion_r47173816
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/StateSpec.scala ---
    @@ -91,115 +105,125 @@ sealed abstract class StateSpec[KeyType, ValueType, 
StateType, EmittedType] exte
     /**
      * :: Experimental ::
      * Builder object for creating instances of 
[[org.apache.spark.streaming.StateSpec StateSpec]]
    - * that is used for specifying the parameters of the DStream 
transformation `trackStateByKey`
    + * that is used for specifying the parameters of the DStream 
transformation `mapWithState`
      * that is used for specifying the parameters of the DStream transformation
    - * `trackStateByKey` operation of a
    + * `mapWithState` operation of a
      * [[org.apache.spark.streaming.dstream.PairDStreamFunctions pair 
DStream]] (Scala) or a
      * [[org.apache.spark.streaming.api.java.JavaPairDStream JavaPairDStream]] 
(Java).
      *
      * 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 emittedRecordDStream = 
keyValueDStream.trackStateByKey[StateType, EmittedDataType](
    - *        StateSpec.function(trackingFunction).numPartitions(10))
    + *    val spec = StateSpec.function(mappingFunction).numPartitions(10)
    + *
    + *    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 `Integer` now


---
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]

Reply via email to