Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Motivation

Now many watermark-related features such as the watermark alignment have been implemented on the datastream API, and it is very convenient and flexible to configure and use these features through the datastream API. However, there is currently no way to use these features through table API & SQL.

This FLIP proposes to enhance the availability of watermark options of table API & SQL.

Proposed Change

Current capabilities of watermark on table API & SQL

The event time attribute is defined using a WATERMARK statement in CREATE table DDL. A watermark statement defines a watermark generation expression on an existing event time field, which marks the event time field as the event time attribute. Some examples:

...

These are all the capabilities of watermark on the table API. The following table shows a more detailed comparison:


datastream API

table API & SQL

Monotonously Increasing Timestamps

supported

supported

Fixed Amount of Lateness

supported

supported

Dealing With Idle Sources

supported

limited support

Watermark Alignment

supported

unsupport

Periodic Watermark Generator

supported

supported

Punctuated Watermark Generator

supported

unsupport


Note that although the syntax to use watermark in SQL is the same, the location of generating watermark may be different. The watermark of the source that implements the `SupportsWatermarkPushDown` interface is generated in the source operator, while the watermark of the source that does not implement the `SupportsWatermarkPushDown` interface is generated in a downstream operator named ‘WatermarkAssigner’.If the watermark is generated in the downstream 'WatermarkAssigner' operator, many watermark-related features, such as watermark alignment, will can not be implemented. So the features that this flip intends to support are only for those sources that implement the `SupportsWatermarkPushDown` interface.

Watermark-related features that this flip intends to support

At the table API & SQL level, the watermark is closely related to each source table, so we plan to use the table-scan predicate's hint named ‘WATERMARK_PARAMS’ to extend these features.

1.Configurable watermark emit strategy

On datastream API, we can decide whether to emit a watermark periodically or emit a watermark for each event by code logic from the implementation of the WatermarkGenerator interface:

Code Block
languagejava
linenumberstrue

@Public
public interface WatermarkGenerator<T> {

    /**
    * Called for every event, allows the watermark generator to examine
    * and remember the event timestamps, or to emit a watermark based on
    * the event itself.
    */
    void onEvent(T event, long eventTimestamp, WatermarkOutput output);

    /**
    * Called periodically, and might emit a new watermark, or not.
    *
    * <p>The interval in which this method is called and Watermarks
    * are generated depends on {@link ExecutionConfig#getAutoWatermarkInterval()}.
    */
    void onPeriodicEmit(WatermarkOutput output);
}

...

For the 'ON_EVENT' strategy,  option ‘emit-gap-on-event’ can configure how many events to emit a watermark, the default value is 1. We will also add a global parameter 'table.exec.watermark-emit.gap' to achieve the same goal, which will be valid for each source and will ease the user's configuration to some extent.

2.Dealing with idle sources

On datastream API, We can configure idle-timeout  to handle idle sources in the following way:

...

Code Block
languagesql
select ... from source_table /*+ WATERMARK_PARAMS('idle-timeout'='1min') */

3.Watermark alignment

On datastream API,We can use watermark alignment feature in the following way :

...

Of course, users can choose some of the items to configure according to their needs.


Migration Plan and Compatibility

This feature is biased towards adding more support in Table API & SQL, so there are no compatibility-related issues.

If some of the features are not supported, such as the watermark alignment feature on Kinesis connector, it will behave as FLIP-182 [2] and FLIP-217 [3] designed.

 

Rejected Alternatives

Adding watermark related options in the SQL DDL of watermark column

This idea is like extending FLIP-66[1]. However, since we already have many options for watermark related features, this would make the DDL complex and lengthy.

Adding watermark related options in the connector options

Watermark related options should be treated as a general feature for reading from message queue or even files, these options shall not be part of the connector options.

...