Creating a SQL Job

Sample Code

You can use the API to use the POST method to submit a stream SQL job in JSON format. Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import com.huaweicloud.cs.java.v1.client.ApiException;
import com.huaweicloud.cs.java.v1.JobApi;


JobApi apiInstance = new JobApi(apiClient);//apiClient is created when initializing a CS API client.
String xProjectId = "xProjectId_example"; // String | Project ID used for obtaining the token for the project.
SubmitSqlJobRequest body = new SubmitSqlJobRequest(); // SubmitSqlJobRequest | Request body in the JSON format.
try {
    JobStatusResponse result = apiInstance.submitSqlJob(xProjectId, body);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling JobApi#submitSqlJob");
    System.err.println(e.getResponseBody());
    e.printStackTrace();
}

Parameter Description

Table 1 Parameters

Parameter

Mandatory

Type

Description

xProjectId

Yes

String

Project ID. This parameter is used to obtain the token for the project.

body

Yes

Array of objects

Request body in the JSON format. For details about parameter types, see Table 2.

Table 2 Parameters involved in SubmitSqlJobRequest

Parameter

Mandatory

Type

Description

name

Yes

String

Job name.

desc

No

String

Job description.

templateId

No

Integer

Job template ID.

  • If template_id and sql_body are both specified, sql_body takes precedence.
  • If template_id is not empty and sql_body is empty, the sql_body field is filled with the value of template_id.

clusterId

No

Integer

Resource ID of an exclusive cluster. Ensure that the current user has been authorized to use resources of the exclusive cluster.

sqlBody

No

String

Stream SQL statement, which includes at least the following three parts: source, query, and sink.

runMode

Yes

RunModeEnum

Job running mode. A job can run on a shared or exclusive cluster or an edge node. Possible values are:

  • shared_cluster
  • exclusive_cluster
  • edge_node

spuNumber

No

Integer

Number of SPUs selected for a job.

  • Minimum value: 2
  • Maximum value: 400

parallelNumber

No

Integer

Number of parallel jobs set by a user.

  • Minimum value: 1
  • Maximum value: 2000

checkpointEnabled

No

Boolean

Whether to enable the automatic job snapshot function. The value can be true (enabled) or false (disabled). The default value is false.

checkpointMode

No

CheckpointModeEnum

Snapshot mode. The options are as follows:

  • exactly_once
  • at_least_once

checkpointInterval

No

Integer

Snapshot interval, expressed by seconds. The default value is 10.

obsBucket

No

String

OBS path where users are authorized to save the snapshot. This parameter is used only when checkpoint_enabled is set to true.

logEnabled

No

Boolean

Whether to enable the function of uploading job logs to users' OBS buckets. The default value is false.

smnTopic

No

String

If a job fails to work, CS pushes alarm information to the SMN topic.

restartWhenException

No

Boolean

Whether to enable the function of restart upon exceptions. The default value is false.

idleStateRetention

No

Integer

Maximum retention duration for the idle state, which defines for how long the state of a key is retained without being updated before it is removed. The parameter value is expressed by seconds. The default value is 3600.

jobType

No

String

Job type. Available options are as follows:

  • If run_mode is set to edge_node, this parameter must be flink_sql_edge_job.
  • If run_mode is set to shared_cluster or exclusive_cluster, this parameter must be flink_sql_job.

edgeGroupIds

No

String

List of edge computing group IDs that are separated by commas (,).

tags

No

String

Job tag.

sysEnterpriseProjectId

No

String

ID of the enterprise project to which a job belongs.

udfJarUrl

No

String

OBS address where the SQL job UDF JAR file is stored.

dirtyDataStrategy

No

String

Dirty data policy of a job.

  • 2:obs-wan-wulan3/jobs: Save.
  • 1: Trigger a job exception.
  • 0: Ignore.
Table 3 Parameters involved in JobStatusResponse

Parameter

Mandatory

Type

Description

messageId

No

String

Message type ID.

message

No

String

Message content.

currentTime

No

Long

Current time, expressed by milliseconds.

payload

No

JobStatusInfo

For details about parameter types, see Table 3.

Table 4 Parameters involved in JobStatusInfo

Parameter

Mandatory

Type

Description

jobId

No

Long

Job ID.

statusName

No

String

Status name.

statusDesc

No

String

Status description.