liboshuai01 commented on code in PR #25624: URL: https://github.com/apache/flink/pull/25624#discussion_r1838350358
########## docs/content.zh/docs/dev/datastream/operators/process_function.md: ########## @@ -26,68 +26,61 @@ under the License. # Process Function -## The ProcessFunction +## ProcessFunction 简介 -The `ProcessFunction` is a low-level stream processing operation, giving access to the basic building blocks of -all (acyclic) streaming applications: +`ProcessFunction` 是一种低级别的流处理操作,基于它用户可以访问(无环)流应用程序的所有基本构建块: - - events (stream elements) - - state (fault-tolerant, consistent, only on keyed stream) - - timers (event time and processing time, only on keyed stream) + - 事件(流元素) + - 状态(容错,一致性,仅在 keyed stream 上) + - 定时器(事件时间和处理时间,仅在 keyed stream 上) -The `ProcessFunction` can be thought of as a `FlatMapFunction` with access to keyed state and timers. It handles events -by being invoked for each event received in the input stream(s). +可以将 `ProcessFunction` 视为一种可以访问 keyed state 和定时器的 `FlatMapFunction`。Flink 为收到的输入流中的每个事件都调用该函数来进行处理。 -For fault-tolerant state, the `ProcessFunction` gives access to Flink's [keyed state]({{< ref "docs/dev/datastream/fault-tolerance/state" >}}), accessible via the -`RuntimeContext`, similar to the way other stateful functions can access keyed state. +对于容错,与其它有状态的函数类似,`ProcessFunction` 可以通过 `RuntimeContext` 访问 Flink 的 [keyed state]({{< ref "docs/dev/datastream/fault-tolerance/state" >}})。 -The timers allow applications to react to changes in processing time and in [event time]({{< ref "docs/concepts/time" >}}). -Every call to the function `processElement(...)` gets a `Context` object which gives access to the element's -event time timestamp, and to the *TimerService*. The `TimerService` can be used to register callbacks for future -event-/processing-time instants. With event-time timers, the `onTimer(...)` method is called when the current watermark is advanced up to or beyond the timestamp of the timer, while with processing-time timers, `onTimer(...)` is called when wall clock time reaches the specified time. During that call, all states are again scoped to the key with which the timer was created, allowing -timers to manipulate keyed state. +定时器允许应用程序对处理时间和 [事件时间]({{< ref "docs/concepts/time" >}}) 中的更改做出反应。 +每次调用 `processElement(...)` 时参数中都会提供一个 `Context` 对象,该对象可以访问元素的事件时间戳和 *TimerService*。 +`TimerService` 可用于为将来特定的事件时间/处理时间注册回调。 +特定事件时间的 `onTimer(...)` 回调函数会在当前对齐的 watermark 超过所注册的时间戳时调用。 +特定处理时间的 `onTimer(...)` 回调函数则会在系统物理时间超过所注册的时间戳时调用。 +在该调用期间,所有状态会被再次绑定到创建定时器时的键上,从而允许定时器操作与之对应的 keyed state。 {{< hint info >}} -If you want to access keyed state and timers you have -to apply the `ProcessFunction` on a keyed stream: +如果想要访问 keyed state 和定时器,需要在 +keyed stream 上使用 `ProcessFunction`。 {{< /hint >}} ```java stream.keyBy(...).process(new MyProcessFunction()); ``` -## Low-level Joins +## 低级别 Join -To realize low-level operations on two inputs, applications can use `CoProcessFunction` or `KeyedCoProcessFunction`. This -function is bound to two different inputs and gets individual calls to `processElement1(...)` and -`processElement2(...)` for records from the two different inputs. +为了在两个输入上实现低级别操作,应用程序可以使用 `CoProcessFunction` 或 `KeyedCoProcessFunction`。 +这些函数绑定两个不同的输入,从两个不同的输入中获取元素并分别调用 +`processElement1(...)` 和 `processElement2(...)` 进行处理。 -Implementing a low level join typically follows this pattern: +实现低级别 join 一般需要遵循以下模式: - - Create a state object for one input (or both) - - Update the state upon receiving elements from its input - - Upon receiving elements from the other input, probe the state and produce the joined result + - 为一个输入(或两者)创建状态对象。 + - 从某个输入接收元素时更新状态。 + - 从另一个输入接收元素时,查询状态并生成 join 结果。 -For example, you might be joining customer data to financial trades, -while keeping state for the customer data. If you care about having -complete and deterministic joins in the face of out-of-order events, -you can use a timer to evaluate and emit the join for a trade when the -watermark for the customer data stream has passed the time of that -trade. +例如,你可能会将客户数据与金融交易进行 join,同时想要保留客户数据的状态。如果你希望即使在出现乱序事件时仍然可以得到完整且确定的 join 结果,你可以通过注册一个定时器在客户数据流的 watermark 已经超过当前这条 finance trade 记录时计算和发送 join 结果。 Review Comment: 是的,已采纳修改。 -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org