Creating a Script
Function
This API is used to create a script. Currently, the following script types are supported: DLI SQL, Flink SQL, RDS SQL, Spark SQL, Hive SQL, DWS SQL, Shell, Presto SQL, ClickHouse SQL, HetuEngine SQL, Python, Impala SQL, and Spark Python.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, no identity policy-based permission required for calling this API.
- Parameter description
Table 1 URI parameter Parameter
Mandatory
Type
Description
project_id
Yes
String
Project ID. For details about how to obtain a project ID, see Project ID and Account ID.
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| workspace | No | String | Workspace ID. For details about how to obtain it, see Instance ID and Workspace ID.
|
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Script name. The value can contain up to 128 characters. Only letters, digits, hyphens (-), and periods (.) are allowed. The script name must be unique. |
| type | Yes | String | Script type.
|
| content | Yes | String | Script content. A maximum of 4 MB is supported. |
| directory | No | String | Directory for storing the script. Access the DataArts Studio console and go to the DataArts Factory page. In the left navigation pane, choose . In the directory tree of the script, you can view the created directories. The default directory is the root directory. |
| connectionName | No | String | Name of the connection associated with the script. This parameter is mandatory when type is set to one of the following: DLISQL, Flink SQL, SparkSQL, HiveSQL, DWSSQL, Shell, PRESTO, ClickHouseSQL, HetuEngineSQL, RDSSQL, ImpalaSQL, PYTHON, or SparkPython. By default, this parameter is left blank. |
| database | No | String | Database associated with an SQL statement. This parameter is available only when type is set to DLISQL, SparkSQL, HiveSQL, DWSSQL, PRESTO, RDSSQL, ClickHouseSQL, ImpalaSQL, or HetuEngineSQL.
|
| queueName | Yes | String | Queue name of the DLI resource. This parameter is available only when type is set to DLISQL. You can obtain the queue information by calling the API for "Querying All Queues" in the Data Lake Insight API Reference. By default, this parameter is left blank. |
| configuration | No | map <String,Object> | User-defined parameter that applies to the script. This parameter is left blank by default. For Python scripts, this parameter specifies the Python version (Python 3 or Python 2). Setting input parameters and setting interactive parameters are optional. This parameter can also be configured when type is set to DLI SQL. For details about the supported configuration items, see conf parameter description in the "Submitting a SQL Job" section of the Data Lake Insight API Reference. |
| description | No | String | Description. The value can contain up to 255 characters. |
| owner | No | String | Owner name. |
| targetStatus | No | String | This parameter is required if the review function is enabled. It indicates the target status of the script. The value can be SAVED, SUBMITTED, or PRODUCTION.
|
| approvers | No | List<JobApprover> | Script approver. This parameter is required if the review function is enabled. For details, see Table 4. |
Response Parameters
None.
Example Request
POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/scripts
{
"name": "echoTimeShell",
"type": "Shell",
"content": "echo a",
"queueName": "default",
"connectionName": "con"
} POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/scripts
{
"name": "echoTimeShell",
"type": "Shell",
"content": "echo a",
"queueName": "default",
"connectionName": "con",
"targetStatus":"SUBMITTED",
"approvers": [
{
"approverName": "userName1"
},
{
"approverName": "userName2"
}
]
} Example Response
Status Code
See Status Codes.
Example Request for Creating a Python Script
POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/scripts
{
"configuration":{
"pythonVersion":"Python 3", // Python version, which can be Python 3 or Python 2.
"inputs":"", // Input parameters.
"arguments":"" // Interactive parameters.
},
"connectionName":"mrs-host", // Data connection.
"content":"## PYTHON \n print('hello world')", // Python script content.
"description":"", // Script description.
"name":"zhangsan-test", // Script name.
"owner":"zhangsan", // Script owner.
"templateVersion":"1.0", // Current version.
"type":"PYTHON", // Script type.
"approvers": [ // Approvers. This optional field is used when the approval mode is enabled.
{
"approverName": "userName1"
},
{
"approverName": "userName2"
}
]
} What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot