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
| 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. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Job name. |
| desc | No | String | Job description. |
| templateId | No | Integer | Job 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:
|
| spuNumber | No | Integer | Number of SPUs selected for a job.
|
| parallelNumber | No | Integer | Number of parallel jobs set by a user.
|
| 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:
|
| 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:
|
| 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.
|
| 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. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| jobId | No | Long | Job ID. |
| statusName | No | String | Status name. |
| statusDesc | No | String | Status description. |
Last Article: Querying the Current Release Version of CS
Next Article: Creating a User-Defined Job
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.