All Products
Search
Document Center

Realtime Compute for Apache Flink:Develop an SQL draft

Last Updated:Sep 12, 2024

This topic describes how to develop an SQL draft in the console of fully managed Flink.

Scenarios

When you write code for an SQL draft, you can use various built-in connectors that are provided by fully managed Flink, user-defined functions (UDFs), and custom connectors. For more information about the usage scenarios and methods of built-in connectors, UDFs, and custom connectors, see the following topics:

Procedure

  1. Log on to the console of fully managed Flink and create an SQL draft.

    1. Log on to the Realtime Compute for Apache Flink console.

    2. find the workspace that you want to manage and click Console in the Actions column.

    3. In the left-side navigation pane, click Development > ETL. In the upper-left corner of the SQL Editor page, click New.

    4. On the SQL Scripts tab of the New Draft dialog box, click Blank Stream Draft.

      Fully managed Flink provides various SQL code templates and supports data synchronization. Each code template provides specific scenarios, code samples, and instructions for you. You can click the desired template to quickly learn about the features and related syntax of Flink and implement your business logic. For more information, see Code templates and Data synchronization templates.

    5. Click Next.

    6. In the New Draft dialog box, configure the parameters of the draft. The following table describes the parameters.

      Parameter

      Description

      Name

      The name of the draft that you want to create.

      Note

      The draft name must be unique in the current project.

      Location

      The folder in which the code file of the draft is saved.

      You can also click the 新建文件夹 icon to the right of an existing folder to create a subfolder.

      Engine Version

      The engine version of Flink that is used by the draft. For more information about engine versions, version mappings, and important time points in the lifecycle of each version, see Engine version.

    7. Click Create.

  2. Write DDL and DML statements.

    Note

    The metadata management feature allows you to reuse the table schema that is created in different drafts. When you edit an SQL draft on the SQL Editor page in the console of fully managed Flink, the system automatically completes the fields and table names after you enter only specific characters.

    Sample statements:

    -- Create a source table named datagen_source. 
    CREATE TEMPORARY TABLE datagen_source(
      name VARCHAR
    ) WITH (
      'connector' = 'datagen'
    );
    
    -- Create a result table named blackhole_sink. 
    CREATE TEMPORARY TABLE blackhole_sink(
      name  VARCHAR
    ) WITH (
      'connector' = 'blackhole'
    );
    
    -- Insert data from the source table datagen_source into the result table blackhole_sink. 
    INSERT INTO blackhole_sink
    SELECT
      name
    from datagen_source;
    1. On the right-side of the SQL Editor page, click a desired tab to view or enter the configuration information on the tab based on your business requirements.

      Tab name

      Configuration description

      Configurations

      • Engine Version: the version of the Flink engine that you select when you create the draft. For more information about engine versions, see Engine versions and Lifecycle policies. We recommend that you use a recommended version or a stable version. Valid values:

        • Recommend: the latest minor version of the current major version.

        • Stable: the latest minor version of the major version that is still in use within the validity period for renewal. Defects in previous versions are fixed.

        • Normal: other minor versions that are still in use within the validity period for renewal.

        • Deprecated: the version that expires.

      • Additional Dependencies: the additional dependencies that are used in the draft, such as temporary functions.

      Structure

      • Flow Diagram: the flow diagram that allows you to view the directions in which data flows.

      • Tree Diagram: the tree diagram that allows you to view the source from which data is processed.

      Versions

      You can view the engine version of the deployment. For more information about the operations that you can perform in the Actions column in the Draft Versions panel, see Manage deployment versions.

  3. Click Save.

  4. Click Validate.

    Check the SQL semantics of the draft, network connectivity, and the metadata information of the tables that are used by the draft. You can also click SQL Advice in the calculated results to view information about SQL risks and related optimization suggestions.

  5. Optional: Click Debug.

    You can enable the debugging feature to simulate deployment running, check outputs, and verify the business logic of SELECT and INSERT statements. This feature improves development efficiency and reduces the risks of poor data quality. For more information, see Debug a deployment.

  6. Click Deploy.

    After the draft development and syntax check are complete, you can deploy the draft to publish the data to the production environment. After the draft is deployed, you can start the deployment for the draft on the O&M > Deployments page to run the deployment. For more information, see Start a deployment.