java.lang.Object
org.apache.flink.streaming.examples.dsv2.watermark.CountSales

public class CountSales extends Object
This example shows how to count the cumulative sales of each product at the moment. In this example, we simulate the creation and propagation of event time watermarks through Watermark.

Please note that Flink provides users with an event time extension to support event time. You can refer to the CountNewsClicks example.

The example uses a DataGeneratorSource as input source and a custom Watermark to propagate the event time in the stream.

Usage:

  • --parallelism <path>The parallelism of the source. The default value is 5.

This example shows how to:

  • How to define and propagate custom event (Watermark) in DataStream API V2

Please note that if you intend to run this example in an IDE, you must first add the following VM options: "--add-opens=java.base/java.util=ALL-UNNAMED". This is necessary because the module system in JDK 17+ restricts some reflection operations.

Please note that the DataStream API V2 is a new set of APIs, to gradually replace the original DataStream API. It is currently in the experimental stage and is not fully available for production.

  • Field Details

    • EVENT_TIME_WATERMARK_DECLARATION

      public static final org.apache.flink.api.common.watermark.LongWatermarkDeclaration EVENT_TIME_WATERMARK_DECLARATION
      Firstly, we define an event time watermark, which represents the time of currently processing event. Since the watermark needs to convey the timestamp, its data type is long. To determine the minimum event time across all watermarks, we utilize the combineFunctionMin() method to combine the watermarks. The default handling strategy is forward, meaning that the watermark will typically be advanced to downstream operators in most scenarios. Thus, we create a WatermarkDeclaration instance that can be used to declare and generate the watermark.
  • Constructor Details

    • CountSales

      public CountSales()
  • Method Details