Built-in code templates
Ververica Cloud provides built-in templates for use case scenarios with functioning code samples and instructions on how to use them. Code templates help you quickly understand the features and related syntax of Ververica Cloud and implement your own business logic. Below, we describe the usage scenarios for code templates and how to use them.
Precautions
Code templates drafts must contain the INSERT INTO
statement in order to be deployed.
Supported code templates
The following sections categorize and provide use case scenarios for the code templates provided by Ververica Cloud.
Basic templates
Template name | Scenario |
---|---|
Create Table | If you want to create a table and save the table in a catalog, you can execute the CREATE TABLE statement. The operation on a table is similar to the operation on a database. |
Create Temporary Table | If you want to use a table only in the current session or an SQL script, you can execute the CREATE TEMPORARY TABLE statement. |
Create Temporary View | If you want to reuse code, create a long query, or write an SQL script to simplify draft development when you develop a Flink SQL draft, you can execute the CREATE TEMPORARY VIEW statement. |
INSERT INTO | If you want to write query results to a table in a downstream storage system, you can execute the INSERT INTO statement. |
STATEMENT SET | If you want to query results to two or more downstream storage systems, you can use the STATEMENT SET syntax. |
Watermark | If you want Ververica Cloud to process out-of-order data as expected, you can use the WATERMARK clause in DDL statements. You can use the WATERMARK clause in a CREATE TABLE DDL statement to create a watermark. This clause defines an expression to generate watermarks based on an existing field and marks the field as a time attribute field. |
Aggregation and analysis templates
Template Name | Scenario |
---|---|
GROUP BY | If you want to aggregate and analyze data in real time, you can use the GROUP BY clause. |
Tumble Window Aggregation | If you want to group time series data and aggregate and analyze the data in each group, you can use the TUMBLE function. |
Hop Window Aggregation | If you want to update data in a window at a specified interval, you can use the HOP function. |
Cumulate Window Aggregation | If you want to view the calculation results of a window in advance, such as viewing the latest result of the window at an interval of one minute, you can use the CUMULATE function. |
Session Window Aggregation | If you want to collect the statistics of data in an active session in real time, you can use a SESSION function. |
Over Window Aggregation | If you want to perform statistical analysis on each element in a window, you can use an OVER window. |
Chained Window Aggregation | If you want to aggregate data of the same stream in different time dimensions, such as 1 minute, 5 minutes, 30 minutes, or 1 hour, you can use cascading windows. |
Deduplication template
Template Name | Scenario |
---|---|
Deduplication | If you want to remove duplicate data from a data stream, you can use the deduplication syntax. |
Top-N templates
Template Name | Scenario |
---|---|
Top-N | If you want to sort the computing results in ascending or descending order based on your business requirements and obtain the first N data records, you can use the Top-N syntax. |
Window Top-N | If you want to sort the computing results in ascending or descending order and obtain the first N data records in a specified time range, you can use the window Top-N syntax. |
Complex event processing (CEP) template
Template Name | Scenario |
---|---|
Pattern Recognizing | If you want to search for a set of event patterns in data streams, you can use the MATCH_RECOGNIZE syntax. |
JOIN templates
Template name | Scenario |
---|---|
Regular Join | If you want to perform a join query on data of a table and a stream table, you can use a regular join. |
Interval Join | If you want to perform a join query on data of a table and a stream table in a specified period of time, you can use an interval join. |
Temporal Join | If you want to perform a join query on data of a stream table and the related time version data in another table, you can use a temporal join. |
Look-up Join | If you want to perform a join query on data of a static dimension table and a stream table, you can use a look-up join. |
Procedure
The following steps demonstrate how to use a code template in Ververica Cloud. In this example, the Create Table template is used.
- On the Dashboard page, open the console for the workspace you want to manage.
- In the Console navigation pane, click SQL editor and choose the Drafts tab.
- Click New to create a new draft.
- From the SQL Scripts in the New Draft dialog box, choose the Create Table code template and click Next.
- Configure the Name, Location, and Engine Version parameters of the Draft based on your needs.
- In the Preview section, write your SQL code.
- Click Create.