Class CountSales
- 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 throughWatermark.Please note that Flink provides users with an event time extension to support event time. You can refer to the
CountNewsClicksexample.The example uses a
DataGeneratorSourceas input source and a customWatermarkto 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCountSales.CumulativeSalesCountSales.CumulativeSalesrepresents the cumulative sales at a certain moment of a product.static classCountSales.OrderPojo class for Order.
-
Field Summary
Fields Modifier and Type Field Description static org.apache.flink.api.common.watermark.LongWatermarkDeclarationEVENT_TIME_WATERMARK_DECLARATIONFirstly, we define an event time watermark, which represents the time of currently processing event.
-
Constructor Summary
Constructors Constructor Description CountSales()
-
-
-
Field Detail
-
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.
-
-