Configure a Streaming SQL job

Updated at:

This topic describes how to configure a Streaming SQL job.

Background information

When configuring a Streaming SQL job, you must specify its dependency libraries. The following table lists the available data source dependency bundles. We recommend using the latest version.

Library name

Version

Release date

Reference string

Description

datasources-bundle

2.0.0 (recommended)

2020-02-26

sharedlibs:streamingsql:datasources-bundle:2.0.0

Supported data sources: Kafka, LogHub, Druid, Tablestore, HBase, JDBC, DataHub, Redis, Kudu, and DTS.

1.9.0

2019-11-20

sharedlibs:streamingsql:datasources-bundle:1.9.0

Supported data sources: Kafka, LogHub, Druid, Tablestore, HBase, JDBC, DataHub, Redis, and Kudu.

1.8.0

2019-10-17

sharedlibs:streamingsql:datasources-bundle:1.8.0

Supported data sources: Kafka, LogHub, Druid, Tablestore, HBase, JDBC, DataHub, and Redis.

1.7.0

2019-07-29

sharedlibs:streamingsql:datasources-bundle:1.7.0

Supported data sources: Kafka, LogHub, Druid, Tablestore, HBase, and JDBC.

Prerequisites

  • You have created a project. For more information, see Project Management.

  • Ensure you have the required resources and data files for the job, such as the JAR package, data file names, and their storage paths.

Procedure

  1. Go to the Projects page in Data Platform.

    1. Log in to the E-MapReduce console with your Alibaba Cloud account.

    2. In the top navigation bar, select the region and resource group.

    3. Click the Data Development tab.

  2. In the row of the project you want to edit, click Edit Job.

  3. Create a Streaming SQL job.

    1. On the left side of the page, right-click the target folder and select Create Job.
    2. In the Create Job dialog box, enter a Job Name and Description for the job, and select Streaming SQL from the Job Type drop-down list.

    3. Click OK.
  4. Edit the job content.

    In the Content section, enter the SQL statements for the job. The following code is an example.

    --- Create a Log Service (SLS) table. 
    CREATE TABLE IF NOT EXISTS ${slsTableName} 
      USING loghub 
      OPTIONS ( 
            sls.project = '${logProjectName}', 
           sls.store = '${logStoreName}', 
           access.key.id = '${accessKeyId}', 
           access.key.secret = '${accessKeySecret}', 
           endpoint = '${endpoint}'
      ); 
    --- Import data into HDFS.
    INSERT INTO 
       ${hdfsTableName} 
    SELECT 
       col1, col2 
    FROM  ${slsTableName} 
    WHERE ${condition}
    Note

    This type of job is submitted by using thestreaming-sql -f {sql_script} command. Thesql_script file contains the SQL statements from the job editor.

  5. Configure dependency libraries and a failure handling policy.

    1. In the upper-right corner, click Job Settings.

    2. On the Shared Libraries and Streaming Task Settings tabs, configure dependency libraries and a failure handling policy.

      Section

      Parameter

      Description

      Dependency libraries

      Libraries

      Jobs rely on dependency libraries for specific data sources. Alibaba Cloud E-MapReduce provides these libraries in a service repository. When creating a job, you must specify a library version.

      You only need to specify the reference string for the required version, such as sharedlibs:streamingsql:datasources-bundle:2.0.0.

      Failure Handling Policy

      On current statement failure

      Sets the action to take if the current statement fails to execute.

      • Execute next statement: If a query statement fails, the job proceeds to the next statement.

      • Terminate job: If a query statement fails, the job terminates.

    3. Click Save to save the job content and its configuration.