Class CountSales
java.lang.Object
org.apache.flink.streaming.examples.dsv2.watermark.CountSales
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCountSales.CumulativeSalesrepresents the cumulative sales at a certain moment of a product.static classPojo class for Order. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.flink.api.common.watermark.LongWatermarkDeclarationFirstly, we define an event time watermark, which represents the time of currently processing event. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
EVENT_TIME_WATERMARK_DECLARATION
public static final org.apache.flink.api.common.watermark.LongWatermarkDeclaration EVENT_TIME_WATERMARK_DECLARATIONFirstly, 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
-
main
- Throws:
Exception
-