Skip to main content

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 nameScenario
Create TableIf 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 TableIf 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 ViewIf 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 INTOIf you want to write query results to a table in a downstream storage system, you can execute the INSERT INTO statement.
STATEMENT SETIf you want to query results to two or more downstream storage systems, you can use the STATEMENT SET syntax.
WatermarkIf 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 NameScenario
GROUP BYIf you want to aggregate and analyze data in real time, you can use the GROUP BY clause.
Tumble Window AggregationIf you want to group time series data and aggregate and analyze the data in each group, you can use the TUMBLE function.
Hop Window AggregationIf you want to update data in a window at a specified interval, you can use the HOP function.
Cumulate Window AggregationIf 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 AggregationIf you want to collect the statistics of data in an active session in real time, you can use a SESSION function.
Over Window AggregationIf you want to perform statistical analysis on each element in a window, you can use an OVER window.
Chained Window AggregationIf 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 NameScenario
DeduplicationIf you want to remove duplicate data from a data stream, you can use the deduplication syntax.

Top-N templates​

Template NameScenario
Top-NIf 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-NIf 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 NameScenario
Pattern RecognizingIf you want to search for a set of event patterns in data streams, you can use the MATCH_RECOGNIZE syntax.

JOIN templates​

Template nameScenario
Regular JoinIf you want to perform a join query on data of a table and a stream table, you can use a regular join.
Interval JoinIf 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 JoinIf 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 JoinIf 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.

  1. Log in to Ververica Cloud.
  2. Navigate to the workspace that you want to work with.
  3. Open the SQL Editor and click New to create a new draft.
  4. From the SQL Scripts in the New Draft dialog box, choose the Create Table code template and click Next.

CREATE TABLE code template selection

  1. Configure the Name, Location, and Engine Version parameters of the Draft based on your needs. In the Preview section, write your SQL code.

SQL Draft Parameters

  1. Click Create.