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

    https://github.com/apache/spark/pull/9256#discussion_r44205053
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/StateSpec.scala ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.streaming
    +
    +import scala.reflect.ClassTag
    +
    +import org.apache.spark.annotation.Experimental
    +import org.apache.spark.api.java.JavaPairRDD
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.{HashPartitioner, Partitioner}
    +
    +
    +/**
    + * :: Experimental ::
    + * Abstract class representing all the specifications of the DStream 
transformation
    + * `trackStateByKey` operation of a
    + * [[org.apache.spark.streaming.dstream.PairDStreamFunctions pair 
DStream]] (Scala) or a
    + * [[org.apache.spark.streaming.api.java.JavaPairDStream JavaPairDStream]] 
(Java).
    + * Use the [[org.apache.spark.streaming.StateSpec StateSpec.apply()]] or
    + * [[org.apache.spark.streaming.StateSpec StateSpec.create()]] to create 
instances of
    + * this class.
    + *
    + * Example in Scala:
    + * {{{
    + *    val spec = StateSpec(trackingFunction).numPartitions(10)
    + *
    + *    val emittedRecordDStream = 
keyValueDStream.trackStateByKey[StateType, EmittedDataType](spec)
    + * }}}
    + *
    + * Example in Java:
    + * {{{
    + *    StateStateSpec[StateType, EmittedDataType] spec =
    + *      StateStateSpec.create[StateType, 
EmittedDataType](trackingFunction).numPartition(10);
    + *
    + *    JavaDStream[EmittedDataType] emittedRecordDStream =
    + *      javaPairDStream.trackStateByKey[StateType, EmittedDataType](spec);
    + * }}}
    + */
    +@Experimental
    +sealed abstract class StateSpec[K, V, S, T] extends Serializable {
    +
    +  /** Set the RDD containing the initial states that will be used by 
`trackStateByKey`*/
    --- End diff --
    
    @rxin Can you comment on the builder pattern used by StateSpec? @pwendell 
Correct me if I am wrong but one point of confusion for him was that there was 
no reference to the tracking function in the API of the StateSpec class (e.g. 
no setter method for the function). This is because the function is specified 
though the StateSpec object's apply/create method. The reason I did it this way 
was to force the user to specify the function to create a spec, as that is the 
only must-provide parameter for `trackStateByKey`
    
    Two options to avoid the confusion are
    1. Add a setter for the function instead of taking a function through 
StateSpec.apply(). So instead of `StateSpec(func)` the user will be doing 
`StateSpec.function(func)`. I dont like the latter, more verbose.
    2. Leave it as is and provide better docs (Patrick didnt have the docs to 
look at, now there is).
    @rxin whats your call. 


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