You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/03 17:25:06 UTC

[GitHub] [flink] XBaith commented on a change in pull request #11979: [FLINK-17291][docs] Translate 'docs/training/event_driven.zh.md' to C…

XBaith commented on a change in pull request #11979:
URL: https://github.com/apache/flink/pull/11979#discussion_r419131197



##########
File path: docs/training/event_driven.zh.md
##########
@@ -29,19 +29,18 @@ under the License.
 
 ## Process Functions
 
-### Introduction
+### 介绍
 
-A `ProcessFunction` combines event processing with timers and state, making it a powerful building
-block for stream processing applications. This is the basis for creating event-driven applications
-with Flink. It is very similar to a `RichFlatMapFunction`, but with the addition of timers.
+`ProcessFunction` 将事件处理与 Timer 和 State 结合在一起,使其成为流处理应用的强大构建模块。
+这是使用 Flink 创建事件驱动的应用程序的基础。它和 `RichFlatMapFunction` 十分相似, 但是增加了 Timer。
 
-### Example
+### 实例

Review comment:
       Do you mean “示例” instead of “实例”?

##########
File path: docs/training/event_driven.zh.md
##########
@@ -29,19 +29,18 @@ under the License.
 
 ## Process Functions
 
-### Introduction
+### 介绍
 
-A `ProcessFunction` combines event processing with timers and state, making it a powerful building
-block for stream processing applications. This is the basis for creating event-driven applications
-with Flink. It is very similar to a `RichFlatMapFunction`, but with the addition of timers.
+`ProcessFunction` 将事件处理与 Timer 和 State 结合在一起,使其成为流处理应用的强大构建模块。
+这是使用 Flink 创建事件驱动的应用程序的基础。它和 `RichFlatMapFunction` 十分相似, 但是增加了 Timer。
 
-### Example
+### 实例
 
-If you've done the
-[hands-on exercise]({% link training/streaming_analytics.zh.md %}#hands-on)
-in the [Streaming Analytics training]({% link training/streaming_analytics.zh.md %}),
-you will recall that it uses a `TumblingEventTimeWindow` to compute the sum of the tips for
-each driver during each hour, like this:
+如果你已经体验了
+[流式分析训练]({% link training/streaming_analytics.zh.md %})
+的[动手实践]({% link training/streaming_analytics.zh.md %}#hands-on),
+你会忆起,它是采用 `TumblingEventTimeWindow` 来计算每个小时内每个司机的小费总和,

Review comment:
       “忆起”还是说“想起”,我个人觉得“想起”读起来更符合我们平常的说法。亦或者说意译成“你应该记得”

##########
File path: docs/training/event_driven.zh.md
##########
@@ -51,8 +50,8 @@ DataStream<Tuple3<Long, Long, Float>> hourlyTips = fares
         .process(new AddTips());
 {% endhighlight %}
 
-It is reasonably straightforward, and educational, to do the same thing with a
-`KeyedProcessFunction`. Let us begin by replacing the code above with this:
+使用 `KeyedProcessFunction` 去实现相同的效果是合理、直接且有学习意义的。

Review comment:
       ```suggestion
   使用 `KeyedProcessFunction` 去实现相同的操作更加直接且更有学习意义。
   ```

##########
File path: docs/training/event_driven.zh.md
##########
@@ -202,52 +196,48 @@ public void onTimer(
 }
 {% endhighlight %}
 
-Observations:
+观察:
 
-* The `OnTimerContext context` passed in to `onTimer` can be used to determine the current key.
+* 传递给 `onTimer` 的 `OnTimerContext context` 可用于确定当前 key。
 
-* Our pseudo-windows are being triggered when the current watermark reaches the end of each hour, at
-  which point `onTimer` is called. This onTimer method removes the related entry from `sumOfTips`,
-  which has the effect of making it impossible to accommodate late events. This is the equivalent of
-  setting the allowedLateness to zero when working with Flink's time windows.
+* 我们的 pseudo-windows 在当前 Watermark 到达每小时结束时触发,此时调用 `onTimer`。
+  这个 `onTimer` 方法从 `sumOfTips` 中删除相关的条目,这样做的效果是不可能容纳延迟的事件。
+  这相当于在使用 Flink 的时间窗口时将 allowedLateness 设置为零。
 
-### Performance Considerations
+### 性能考虑
 
-Flink provides `MapState` and `ListState` types that are optimized for RocksDB. Where possible,
-these should be used instead of a `ValueState` object holding some sort of collection. The RocksDB
-state backend can append to `ListState` without going through (de)serialization, and for `MapState`, each
-key/value pair is a separate RocksDB object, so `MapState` can be efficiently accessed and updated.
+在可能的情况下,应该使用这些对象,而不是持有某种集合的 `ValueState` 对象。
+Flink 提供了为 RocksDB 优化的 `MapState` 和 `ListState` 类型。
+在可能的情况下,应该使用这些对象,而不是持有某种集合的 `ValueState` 对象。
+RocksDB State Backend 可以附加到 `ListState`,而无需进行(反)序列化,
+对于 `MapState`,每个 key/value 都是一个单独的 RocksDB 对象,因此可以有效地访问和更新 `MapState`。
 
 {% top %}
 
 ## Side Outputs
 
-### Introduction
+### 介绍
 
-There are several good reasons to want to have more than one output stream from a Flink operator, such as reporting:
+有几个很好的理由希望从 Flink operator 获得多个输出流,如下报告条目:

Review comment:
       ```suggestion
   有几个很好的理由希望从 Flink 算子获得多个输出流,如下报告条目:
   ```

##########
File path: docs/training/event_driven.zh.md
##########
@@ -269,38 +259,35 @@ SingleOutputStreamOperator hourlyTips = fares
 hourlyTips.getSideOutput(lateFares).print();
 {% endhighlight %}
 
-Alternatively, you can use two OutputTags with the
-same name to refer to the same side output, but if you do, they must have the same type.
+或者,可以使用两个同名的 OutputTag 来引用同一个旁路输出,但如果这样做,它们必须具有相同的类型。
 
 {% top %}
 
-## Closing Remarks
+## 结语
 
-In this example you have seen how a `ProcessFunction` can be used to reimplement a straightforward time
-window. Of course, if Flink's built-in windowing API meets your needs, by all means, go ahead and
-use it. But if you find yourself considering doing something contorted with Flink's windows, don't
-be afraid to roll your own.
+在本例中,你已经了解了如何使用 `ProcessFunction` 重新实现一个简单的时间窗口。
+当然,如果 Flink 内置的窗口 API 能够满足你的开发需求,那么一定要优先使用它。
+但如果你发现自己在考虑用 Flink 的窗口做些错综复杂的事情,不要害怕自己动手。
 
-Also, `ProcessFunctions` are useful for many other use cases beyond computing analytics. The hands-on
-exercise below provides an example of something completely different.
+此外,`ProcessFunctions` 对于计算分析之外的许多其他用例也很有用。
+下面的实践练习提供了一个完全不同的例子。
 
-Another common use case for ProcessFunctions is for expiring stale state. If you think back to the
-[Rides and Fares Exercise](https://github.com/apache/flink-training/tree/{% if site.is_stable %}release-{{ site.version_title }}{% else %}master{% endif %}/rides-and-fares),
-where a `RichCoFlatMapFunction` is used to compute a simple join, the sample solution assumes that
-the TaxiRides and TaxiFares are perfectly matched, one-to-one for each `rideId`. If an event is lost,
-the other event for the same `rideId` will be held in state forever. This could instead be implemented
-as a `KeyedCoProcessFunction`, and a timer could be used to detect and clear any stale state.
+ProcessFunctions 的另一个常见用例是过期过时 State。如果你回想一下
+[Rides and Fares Exercise](https://github.com/apache/flink-training/tree/{% if site.is_stable %}release-{{ site.version_title }}{% else %}master{% endif %}/rides-and-fares),
+其中使用 `RichCoFlatMapFunction` 来计算简单 Join,那么示例解决方案假设 TaxiRides 和 TaxiFares 
+完全匹配,每个 `rideId` 一对一。如果某个事件丢失,则同一 `rideId` 的另一个事件将永远保持 State。
+这可以作为 `Keyedcomprocessfunction` 实现,并且可以使用计时器来检测和清除任何过时的 State。

Review comment:
       ```suggestion
   这可以作为 `KeyedCoProcessFunction` 实现,并且可以使用计时器来检测和清除任何过时的 State。
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org