T
- The type of the elements to which this assigner assigns timestamps.public interface AssignerWithPunctuatedWatermarks<T> extends TimestampAssigner<T>
AssignerWithPunctuatedWatermarks
assigns event time timestamps to elements,
and generates low watermarks that signal event time progress within the stream.
Use these class if certain special elements act as markers that signify event time progress, and when you want to emit watermarks specifically at certain events.
For use cases that should periodically emit watermarks based on element timestamps,
use the AssignerWithPeriodicWatermarks
instead.
The following example illustrates how to use this timestamp extractor and watermark generator. It assumes elements carry a timestamp that describes when they were created, and that some elements carry a flag, marking them as the end of a sequence such that no elements with smaller timestamps can come any more.
public class WatermarkOnFlagAssigner implements AssignerWithPunctuatedWatermarks<MyElement> {
public long extractTimestamp(MyElement element, long previousElementTimestamp) {
return element.getSequenceTimestamp();
}
public Watermark checkAndGetNextWatermark(MyElement lastElement, long extractedTimestamp) {
return lastElement.isEndOfSequence() ? new Watermark(extractedTimestamp) : null;
}
}
Timestamps and watermarks are defined as longs
that represent the
milliseconds since the Epoch (midnight, January 1, 1970 UTC).
A watermark with a certain value t
indicates that no elements with event
timestamps x
, where x
is lower or equal to t
, will occur any more.
Watermark
Modifier and Type | Method and Description |
---|---|
Watermark |
checkAndGetNextWatermark(T lastElement,
long extractedTimestamp)
Asks this implementation if it wants to emit a watermark.
|
extractTimestamp
Watermark checkAndGetNextWatermark(T lastElement, long extractedTimestamp)
TimestampAssigner.extractTimestamp(Object, long)
method. If the method returns a positive
value, a new watermark should be emitted. If a negative value is emitted, no new watermark
will be generated.
Note that whenever this method returns a positive value that is larger than the previous value, a new watermark is generated. Hence, the implementation has full control how often watermarks are generated.
For an example how to use this method, see the documentation of
this class
.
Null
, if no watermark should be emitted, or the next watermark to emit.Copyright © 2014–2016 The Apache Software Foundation. All rights reserved.