感谢回复,但是很抱歉我试了一下发现不可以。
无论是使用了`AssignerWithPeriodicWatermarks`的`getCurrentWatermark`还是`AssignerWithPunctuatedWatermarks`的`checkAndGetNextWatermark`,当它们`return
 null`时下游算子拿到的水印都显示为`No 
Watermark`,我在下游算子中打印出`context.currentWatermark()`发现都是`Long.MIN_VALUE`的值。
看了这两个接口文档,不太理解这里的`no new watermark will be 
generated.`是什么意思,一般理解为不会生成新的水印那之前的水印就应该被继续传下去吧,但实际看来是下游接收不到水印(`no watermark`?)。
@tison,你那边是尝试过这种写法吗,如果可以的话,能麻烦给一个简单的demo吗。


感谢帮助!🙏🙏🙏
```
public interface AssignerWithPeriodicWatermarks<T> extends TimestampAssigner<T> 
{

 /**
 * Returns the current watermark. This method is periodically called by the
 * system to retrieve the current watermark. The method may return {@code null} 
to
 * indicate that no new Watermark is available.
 *
 * <p>The returned watermark will be emitted only if it is non-null and its 
timestamp
 * is larger than that of the previously emitted watermark (to preserve the 
contract of
 * ascending watermarks). If the current watermark is still
 * identical to the previous one, no progress in event time has happened since
 * the previous call to this method. If a null value is returned, or the 
timestamp
 * of the returned watermark is smaller than that of the last emitted one, then 
no
 * new watermark will be generated.
 *
 * <p>The interval in which this method is called and Watermarks are generated
 * depends on {@link ExecutionConfig#getAutoWatermarkInterval()}.
 *
 * @see org.apache.flink.streaming.api.watermark.Watermark
 * @see ExecutionConfig#getAutoWatermarkInterval()
 *
 * @return {@code Null}, if no watermark should be emitted, or the next 
watermark to emit.
 */
 @Nullable
 Watermark getCurrentWatermark();
}
```


 原始邮件 
发件人: tison<[email protected]>
收件人: user-zh<[email protected]>
发送时间: 2020年4月16日(周四) 20:33
主题: Re: 为消息分配时间戳但不想重新分配水印


在 getCurrentWatermark 里返回 null 就行了,会 forward 此前的 watermark 的。另外语义上使用 
AssignerWithPunctuatedWatermarks 会更合适一点。 Best, tison. taowang 
<[email protected]> 于2020年4月16日周四 下午5:13写道: > Hello,大家好: > 在flink > 
stream中我这里遇到一个需求是,想到对上一个算子输出的消息重新分配时间戳,但此时我不想重新分配水印。在从kafka读取消息时我已经添加了水印。 > 
为了实现这个功能,我想有两种方法: > 1. 在算子输出后面重新为消息分配水印:看到flink > 
stream暂时只有`assignTimestampsAndWatermarks`方法,这里面要实现两个接口:`getCurrentWatermark`和`extractTimestamp`。我只想实现`extractTimestamp`而不想管水印相关的`getCurrentWatermark
 > `这个方法。因为在加水印前多并行度会造成乱序从而使水印增长过快。 > 2. > 
在上一个算子输出时指定这个消息的时间戳,但我只看到在`SourceFunction`里才有`collectWithTimestamp`之类的方法,在正常的比如`ProcessFunction`里是只有`collect`方法。
 > > > 我现在只能使用`assignTimestampsAndWatermarks` > 
去重新分配水印,但这限制了我前面的算子并行度都必须设置为1,请问大家有什么好的办法吗? > 感谢解答!

回复