Creating a Flink Streaming SQL Job

This section describes how to create a Flink streaming SQL job. Flink SQL provides users a method for compiling jobs based on their logic requirements. SQL-based business logic expression facilitates service implementation. Currently, you can use the SQL editor or visual editor to edit Flink SQL statements for Flink streaming SQL jobs. This section describes how to use the SQL editor to edit a Flink streaming SQL job.

For details about the visual editor, see Visual Editor.

Prerequisites

You have prepared the data input and data output channels. For details, see Preparing Data.

Procedure

  1. You can create a Flink streaming SQL job on any of the following four pages: Overview, Job Management, Edit, and Template Management.

    • Overview
      1. In the navigation tree on the left pane of the CS management console, click Overview to switch to the Overview page.
        Figure 1 Creating a job on the Overview page
      2. Click Create Job to switch to the Create Job dialog box.
    • Job Management
      1. In the navigation tree on the left pane of the CS management console, choose Job Management to switch to the Job Management page.
        Figure 2 Creating a job on the Job Management page
      2. On the Job Management page, click Create Job to switch to the Create Job dialog box.
    • Edit
      1. In the navigation tree on the left pane of the CS management console, choose Job Management to switch to the Job Management page.
      2. In the row where a created Flink streaming SQL job is located, click Edit under Operation to enter the Edit page.
        Figure 3 Creating a Flink streaming SQL job on the Edit page
      3. Click More > Save As. The Job Save as dialog box is displayed.
    • Template Management
      1. In the navigation tree on the left pane of the CS management console, choose Template Management to switch to the Template Management page.
      2. In the row where the desired template is located, click Create Job under Operation.
        Figure 4 Creating a job on the Template Management page

  2. Specify job parameters.

    Figure 5 Creating a Flink streaming SQL job
    Table 1 Job parameters

    Parameter

    Description

    Type

    Set Type to Flink Streaming SQL Job. You will need to start jobs by compiling SQL statements.

    Name

    Name of a job. Enter 1 to 57 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

    NOTE:

    The job name must be globally unique.

    Description

    Description of a job. It can be up to 512 characters long.

    Editor

    SQL Editor and Visual Editor are both available. SQL Editor is used by default.

    Template

    This parameter is only used when Editor is set to SQL Editor.

    You can select a sample template or a custom job template. For details about templates, see Job Template.

  3. For Enterprise Project, select an enterprise project that you created on the Enterprise Management console.

    For details about how to create an enterprise project on the Enterprise Management console, see Creating an Enterprise Project in the Enterprise Management User Guide.

    The system also has a built-in enterprise project, default. If you do not select an enterprise project for the job, the default project is used instead.

    During job creation, if the job is successfully bound to an enterprise project, the job has been created. If the binding fails, the system sends an alarm and the job fails to be created.

    When you delete a job, the association between the job and its enterprise project is automatically deleted as well.

  4. (Optional) Add tags for the job. In this step, configure the parameters in the following table as required. The tags are optional. If you do not need tags, skip this step.

    Table 2 Tag parameters

    Parameter

    Description

    Tag key

    You can perform the following operations:

    • Click the text box and select a predefined tag key from the drop-down list.
      NOTE:

      To add a predefined tag, you need to create one on TMS and select it from the Tag key drop-down list. You can click View Predefined Tag to enter the Predefined Tag page of TMS. Then, click Create Tag to create a predefined tag. For details, see section Creating Predefined Tags in the Tag Management Service User Guide.

    • Enter a tag key in the text box.
      NOTE:

      A tag key contains a maximum of 36 characters. The first and last characters cannot be spaces. The following characters are not allowed: =*,<>\|/

    Tag value

    You can perform the following operations:

    • Click the text box and select a predefined tag value from the drop-down list.
    • Enter a tag value in the text box.
      NOTE:

      A tag value contains a maximum of 43 characters. The first and last characters cannot be spaces. The following characters are not allowed: =*,<>\|/

    • A maximum of 10 tags can be added.
    • Only one tag value can be added to a tag key.
    • The key name must be unique in the same resource.

  5. Click OK to enter the Edit page.
  6. Edit a job.

    Figure 6 Editing a job

    In the SQL statement editing area, enter SQL statements to implement business logic. For details about how to compile SQL statements, see the Cloud Stream Service SQL Syntax Reference.

  7. Click Check Semantics.

    • You can only debug, submit, or start a job after semantic verification succeeds.
    • If verification is successful, the message "The SQL semantic verification is complete. No error." will be displayed.
    • If verification fails, a red "X" mark will be displayed in front of each SQL statement that produced an error. You can move the cursor to the "X" mark to view error details and change the SQL statement as prompted.

  8. Set job running parameters.

    Figure 7 Setting Running Parameters
    Table 3 Running parameters

    Parameter

    Description

    SPUs

    Stream Processing Unit (SPU) is the pricing unit for CS. An SPU consists of 1 vCPU compute and 4 GB memory.

    Parallelism

    Number of tasks where CS jobs can simultaneously run

    NOTE:

    The value of Parallelism must not exceed the value obtained through the following formula: 4 x (Number of SPUs – 1).

    Enable Checkpoint

    Whether to enable job snapshots. If this function is enabled, jobs can be restored based on the checkpoints.

    The following two parameters are valid after Enable Checkpoint is selected:
    • Checkpoint Interval (s) is the number of seconds between when new checkpoints are created. The parameter value ranges from 1 to 999999, and the default value is 10.
    • Checkpoint Mode can be set to either of the following values:
      • At least once: Events are processed at least once.
      • Exactly once: Events are processed only once.

    Save Job Log

    Whether to save the job running logs to OBS
    NOTE:

    If both Enable Checkpoint and Save Job Log are selected, you only need to authorize OBS once.

    OBS Bucket

    This parameter is valid only when Enable Checkpoint or Save Job Log is selected.

    Select an OBS bucket to store checkpoint and job logs.

    If the selected OBS bucket is not authorized, click Authorize OBS.

    Alarm Generation upon Job Exception

    Whether to report job exceptions, for example, abnormal job running or exceptions due to an insufficient balance, to users via SMS or email

    Auto Restart upon Exception

    Whether to enable automatic restart. If this function is enabled, CS automatically restarts any job that has become abnormal.

    Idle State Retention Time

    Defines for how long the state of a key is retained without being updated before it is removed in GroupBy or Window. The default value is 1 hour.

    Topic Name

    This parameter is only used when Alarm Generation upon Job Exception is selected.

    Select a user-defined SMN topic. For details about how to customize SMN topics, see Creating a Topic in the Simple Message Notification User Guide.

    Dirty Data Policy

    Select a policy for processing dirty data. Available options are as follows: Ignore, Trigger a job exception, and Save. The default value is Ignore.

    Cluster

    Retain the default setting Shared cluster. Alternatively, you can select a user-defined exclusive cluster. For details about how to create a user-defined exclusive cluster, see Creating a Cluster Billed on a Per-per-Use Basis.

    NOTE:

    During job creation, a sub-user can only select a cluster that has been allocated to the user. For details about how to allocate a cluster to a sub-user, see Modifying a Sub-user.

    UDF JAR

    This parameter is valid only when you select an exclusive cluster for Cluster.

    In SQL, you can call a user-defined function that is inserted into a JAR file.

    For details about UDFs, see User-Defined Functions in the Cloud Stream Service SQL Syntax Reference.

  9. Click Save.
  10. Click Submit. On the displayed Job Configurations page, click OK to submit and start the job.

    After you click OK to submit a job, the system automatically switches to the Job Management page, and the created job is displayed in the job list. You can view the job status in the Status column. After a job is successfully submitted, the job status will change from Submitting to Running.

    If the job status is Submission failed or Running exception, the job submission failed or the job did not execute successfully. In this case, you can move the cursor over the status icon in the Status column of the job list to view the error details. You can click to copy these details. After handling the fault based on the provided information, resubmit the job.

    Other buttons are as follows:

    • Debug: indicates to perform job debugging. For details, see Debugging a Job.
    • Format SQL: indicates to format the SQL statement. After clicking Format SQL, you need to edit SQL statements again.
    • More > Modify Name and Description: indicates to modify the job name and description.
    • More > Save As: indicates to save the created job as a new job.
    • More > Set as Template: indicates to set the created job as a job template.
    • More > Theme Settings: indicates to set the theme related parameters, including Font Size, Wrap, and Page Style.
    • More > Help: The help center provides SQL syntax reference for users.