yangyichao-mango commented on a change in pull request #12665:
URL: https://github.com/apache/flink/pull/12665#discussion_r456855949
##########
File path: docs/dev/event_timestamps_watermarks.zh.md
##########
@@ -175,200 +137,243 @@ withTimestampsAndWatermarks
</div>
</div>
+使用 `WatermarkStrategy` 去获取流并生成带有时间戳的元素和 watermark 的新流时,如果原始流已经具有时间戳或
watermark,则新指定的时间戳分配器将覆盖原有的时间戳和 watermark。
-#### **With Periodic Watermarks**
+## 处理空闲数据源
-`AssignerWithPeriodicWatermarks` assigns timestamps and generates watermarks
periodically (possibly depending
-on the stream elements, or purely based on processing time).
+如果数据源中的某一个分区/分片在一段时间内未发送事件数据,则意味着 `WatermarkGenerator` 也不会获得任何新数据去生成
watermark。我们称这类数据源为*空闲输入*或*空闲源*。在这种情况下,当某些其他分区仍然发送事件数据的时候就会出现问题。由于下游算子
watermark 的计算方式是取所有不同的上游并行数据源 watermark 的最小值,则其 watermark 将不会发生变化。
-The interval (every *n* milliseconds) in which the watermark will be generated
is defined via
-`ExecutionConfig.setAutoWatermarkInterval(...)`. The assigner's
`getCurrentWatermark()` method will be
-called each time, and a new watermark will be emitted if the returned
watermark is non-null and larger than the previous
-watermark.
+为了解决这个问题,你可以使用 `WatermarkStrategy` 来检测空闲输入并将其标记为空闲状态。`WatermarkStrategies`
为此提供了一个工具接口:
-Here we show two simple examples of timestamp assigners that use periodic
watermark generation. Note that Flink ships with a
`BoundedOutOfOrdernessTimestampExtractor` similar to the
`BoundedOutOfOrdernessGenerator` shown below, which you can read about
[here]({{ site.baseurl
}}/dev/event_timestamp_extractors.html#assigners-allowing-a-fixed-amount-of-lateness).
+<div class="codetabs" markdown="1">
+<div data-lang="java" markdown="1">
+{% highlight java %}
+WatermarkStrategies
+ .<Tuple2<Long, String>>forBoundedOutOfOrderness(Duration.ofSeconds(20))
+ .withIdleness(Duration.ofMinutes(1))
+ .build();
+{% endhighlight %}
+</div>
+<div data-lang="scala" markdown="1">
+{% highlight scala %}
+WatermarkStrategies
+ .forBoundedOutOfOrderness[(Long, String)](Duration.ofSeconds(20))
+ .withIdleness(Duration.ofMinutes(1))
+ .build()
+{% endhighlight %}
+</div>
+</div>
+
+
+## 自定义 WatermarkGenerator
+
+`TimestampAssigner` 是一个可以从事件数据中提取时间戳字段的简单函数,我们无需详细查看其实现。但是
`WatermarkGenerator` 的编写相对就要复杂一些了,我们将在接下来的两小节中介绍如何实现此接口。WatermarkGenerator
接口代码如下:
+
+{% highlight java %}
+/**
+ * The {@code WatermarkGenerator} generates watermarks either based on events
or
Review comment:
Hi,
这里的注释也是源码注释。
----------------------------------------------------------------
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:
[email protected]