Consider a scenario where the watermark is set as the maximum event time observed so far minus 10 seconds. So the following watermarks will be generated.
Now let us assume there is a window counting events for the hour ending at 12 PM. Therefore, the window will wait until there is a watermark with a timestamp of at least 12:00:00 PM before producing results. As a result, Events F and G are considered on-time and will be included in the calculation. Events H and I will not be included in the calculation for the window ending at 12 PM, with Event I being considered late since its event time timestamp is earlier than the current watermark timestamp.
Syntax
Watermarks can be generated directly on sources. The syntax of theWATERMARK clause in RisingWave is as follows:
column_name is a column that is created when generating the source, usually the event time column.
expr specifies the watermark generation strategy. The return type of the watermark must be of type timestamp. A watermark will be updated if the return value is greater than the current watermark.
For example, the watermark generation strategy can be specified as:
- Maximum observed timestamp
- Maximum observed timestamp with a delay
time_unit values include: second, minute, hour, day, month, and year. For more details, see the interval data type under Overview of data types.
Currently, RisingWave only supports using one of the columns from the table as the watermark column. To use nested fields (e.g., fields in
STRUCT), or perform expression evaluation on the input rows (e.g., casting data types), please refer to generated columns.Example
The following query generates the watermark as the latest timestamp observed inorder_time minus 5 seconds.