Creating a Script

Function

This API is used to create a script. Currently, the following script types are supported: DLI SQL, Flink SQL, Spark SQL, Hive SQL, DWS SQL, RDS SQL, and Shell.

URI

  • URI format

    POST /v1/{project_id}/scripts

  • Parameter description
    Table 1 URI parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Message

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

workspace

No

String

Workspace ID.

  • If this parameter is not set, data in the default workspace is queried by default.
  • If you need to query data in other workspaces, this header must be carried.
Table 3 Script parameter description

Parameter

Mandatory

Type

Description

name

Yes

String

Name of the script. It contains a maximum of 128 characters. Only letters, digits, hyphens (-), and periods (.) are allowed. The script name must be unique.

type

Yes

String

Script type. The value can be:

  • FlinkSQL
  • DLISQL
  • SparkSQL
  • HiveSQL
  • DWSSQL
  • RDSSQL
  • Shell

content

Yes

String

Script content. A maximum of 64 KB is supported.

directory

No

String

Directory for storing the script.

Perform the following operations to obtain the directory:

  1. Log in to the management console.
  2. Click Data Lake Factory and choose Development > Develop Script from the list on the left.

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 DLI SQL, Spark SQL, Hive SQL, DWS SQL, or Shell. To obtain the existing connections, refer to the instructions in Querying a Connection List. 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 DLI SQL, Spark SQL, Hive SQL, or DWS SQL.

  • If type is set to DLI SQL, obtain database information by calling the API for Querying All Databases.
  • If type is not set to DLI SQL, connect to the cluster in JDBC mode to query database information. By default, this parameter is left blank.

queueName

No

String

Queue name of the DLI resource. This parameter is available only when type is set to DLI SQL. You can obtain the queue information by calling the API for Querying All Queues. By default, this parameter is left blank.

configuration

No

map <String,Object>

Configuration defined by a user for the job. This parameter is available only when type is set to DLI SQL. For details about the supported configuration items, see conf parameter description. By default, this parameter is left blank.

description

No

String

The description contains a maximum of 255 characters.

Response Message

None.

Example

Create a script.

  • Request
    POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/scripts
    {
    "name":"echoTimeShell",
    "type":"Shell",
    "content":"echo a",
    "connectionName":"con"
    }
  • Success response

    HTTP status code 204

  • Failure response

    HTTP status code 400

    {
        "error_code":"DLF.6247",
        "error_msg":"The script type is not specified."
    }

Status Code

For details about status codes, see Status Codes.