flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KurtYoung <...@git.apache.org>
Subject [GitHub] flink pull request #3510: [FLINK-6023] Fix Scala snippet into Process Functi...
Date Fri, 10 Mar 2017 15:27:31 GMT
Github user KurtYoung commented on a diff in the pull request:

    --- Diff: docs/dev/stream/process_function.md ---
    @@ -176,56 +176,57 @@ public class CountWithTimeoutFunction extends RichProcessFunction<Tuple2<String,
     <div data-lang="scala" markdown="1">
     {% highlight scala %}
    -import org.apache.flink.api.common.state.ValueState;
    -import org.apache.flink.api.common.state.ValueStateDescriptor;
    -import org.apache.flink.streaming.api.functions.ProcessFunction;
    -import org.apache.flink.streaming.api.functions.ProcessFunction.Context;
    -import org.apache.flink.streaming.api.functions.ProcessFunction.OnTimerContext;
    -import org.apache.flink.util.Collector;
    +import org.apache.flink.api.common.state.ValueState
    +import org.apache.flink.api.common.state.ValueStateDescriptor
    +import org.apache.flink.streaming.api.functions.RichProcessFunction
    +import org.apache.flink.streaming.api.functions.ProcessFunction.Context
    +import org.apache.flink.streaming.api.functions.ProcessFunction.OnTimerContext
    +import org.apache.flink.util.Collector
     // the source data stream
    -DataStream<Tuple2<String, String>> stream = ...;
    +val stream: DataStream[Tuple2[String, String]] = ...
     // apply the process function onto a keyed stream
    -DataStream<Tuple2<String, Long>> result = stream
    -    .keyBy(0)
    -    .process(new CountWithTimeoutFunction());
    +val result: DataStream[Tuple2[String, Long]] = stream
    +  .keyBy(0)
    +  .process(new CountWithTimeoutFunction())
    - * The data type stored in the state
    - */
    +  * The data type stored in the state
    +  */
     case class CountWithTimestamp(key: String, count: Long, lastModified: Long)
    - * The implementation of the ProcessFunction that maintains the count and timeouts
    - */
    -class TimeoutStateFunction extends ProcessFunction[(String, Long), (String, Long)] {
    +  * The implementation of the ProcessFunction that maintains the count and timeouts
    +  */
    +class TimeoutStateFunction extends RichProcessFunction[(String, Long), (String, Long)]
       /** The state that is maintained by this process function */
    -  lazy val state: ValueState[CountWithTimestamp] = getRuntimeContext()
    -      .getState(new ValueStateDescriptor<>("myState", clasOf[CountWithTimestamp]))
    +  lazy val state: ValueState[CountWithTimestamp] = getRuntimeContext
    +    .getState(new ValueStateDescriptor[CountWithTimestamp]("myState", classOf[CountWithTimestamp]))
       override def processElement(value: (String, Long), ctx: Context, out: Collector[(String,
Long)]): Unit = {
         // initialize or retrieve/update the state
    +    val (key, _) = value
    --- End diff --
    can we change the name here? since the IDE reports `suspicious shadowing  by a variable
pattern`. Or you can just use value._1 instead.

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 infrastructure@apache.org or file a JIRA ticket
with INFRA.

View raw message