Fully managed Flink provides a rich library of code templates. Each template includes specific use cases, code examples, and instructions to help you get started. You can use these templates to quickly learn Flink features and syntax, and to implement your own business logic. This topic describes the use cases for these code templates and explains how to use them.
Limitations
Code templates require Realtime Compute for Apache Flink with engine version vvr-4.0.12-flink-1.13 or later.
Usage notes
If a template does not contain an INSERT INTO statement, you cannot deploy the resulting job.
Supported templates
The following table describes the templates provided by fully managed Flink and their use cases. For the latest information, refer to the console.
|
Category |
Template name |
Use case |
|
Basic templates |
Create Table |
Use a DDL statement to create a table and save it in a catalog. |
|
Create Temporary Table |
Use a temporary table if you need the table only within the current session or SQL script. |
|
|
Create Temporary View |
Use a temporary view to simplify Flink SQL development by reusing code or organizing long queries and SQL scripts. |
|
|
INSERT INTO |
To write query results to a table in an external storage system for downstream applications, use the INSERT INTO syntax. |
|
|
STATEMENT SET |
To send the results of a query to two or more downstream systems, use the STATEMENT SET syntax. |
|
|
Watermark |
Use watermarks to ensure Flink correctly handles out-of-order data. You define a watermark in a table's DDL by applying a generation expression on an existing field, which marks it as the event time attribute. For more information, see Event time and watermarks. |
|
|
Aggregation and analysis |
GROUP BY |
To perform real-time aggregation and analysis, use the GROUP BY statement. |
|
Tumbling window aggregation |
To group time-series data and run aggregations within each group, use a tumbling window. |
|
|
Sliding window aggregation |
To update data within a window at regular intervals, use a sliding window. |
|
|
Cumulative window aggregation |
To view window results early, such as seeing the latest window result every minute, use a cumulative window. Note
Using a cumulative window with CDC triggers a syntax validation error: |
|
|
Session window aggregation |
To analyze data generated by users during an active session in real time, use a session window. |
|
|
Over window aggregation |
To run statistical analysis on each element within a window, use an over window. |
|
|
Cascading window aggregation |
To aggregate data from the same stream across different time dimensions, such as 1 minute, 5 minutes, 30 minutes, and 1 hour, use a cascading window. |
|
|
Deduplication template |
Deduplication |
To remove duplicate records from a data stream, use the deduplication syntax. |
|
Top-N templates |
Top-N |
To find the top or bottom N records based on business requirements, use the Top-N syntax. |
|
Window Top-N |
To find the top or bottom N records within a specific time range, use the Window Top-N syntax. |
|
|
CEP template |
Complex event processing (CEP) |
To search for a sequence of event patterns in a data stream, use the |
|
Join templates |
Regular join |
To enrich a stream by joining it with data from other streams, use a regular join. |
|
Interval join |
To join records from two streams that fall within a specified time interval, use an interval join. |
|
|
Temporal join |
To join each record from a data stream with corresponding versioned data in a temporal table, use a temporal join. |
|
|
Lookup join |
To join a data stream with a static dimension table, use a lookup join. |
Procedure
This topic uses the Create Table template to demonstrate how to use code templates.
-
Log in to the Realtime Compute for Apache Flink console.
-
Click Console in the Actions column for the target workspace.
-
On the page, click Create.
-
On the SQL Basic Template tab, double-click the target template name, or select the target template and click Next in the lower-right corner.
Available SQL basic templates include Blank Streaming Job Draft, Blank Batch Job Draft (BETA), Create Table, Create Temporary Table, Create Temporary View, and INSERT INTO.
-
As needed, modify the File Name, Storage Location, Engine Version, and SQL code.
For example, select
vvr-6.0.6-flink-1.15for Engine Version, enter theCREATE TABLE orders (order_uid BIGINT, product_id BIGINT, price DECIMAL(32,2), order_time TIMESTAMP(3)) WITH ('connector' = 'datagen')statement in the SQL editor, and then click Create. -
Click Create.
The subsequent operations are the same as the standard job development process. For details, see Job Development Map.