Executing a SparkSql Job
Function
This API is used to execute a Spark SQL job. It is an asynchronous API. After the API is successfully called, the job ID (statement_id) is returned. You can query the job execution result through the API for querying the status of a Spark SQL job.
Calling Method
For details, see Calling APIs.
URI
POST /v2/workspaces/{workspace_id}/spark-sqls
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| workspace_id | Yes | String | Definition: Workspace ID, used for resource isolation. This can be viewed on the workspace page of the console. Constraints: N/A Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition: User token. It is obtained by calling the Obtaining an IAM User Token API. Constraints: N/A Range: The value can contain a maximum of 65,534 characters, with no character type restrictions. Default Value: N/A |
| X-Client-Token | No | String | Definition: Service transaction ID, used for link tracking and preventing duplicate submissions. Constraints: N/A Range: UUID format, 36 characters. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| endpoint_name | Yes | String | Definition: Endpoint name, used to specify the compute engine for running the SparkSql job. This can be viewed on the endpoint management page of the console or obtained by calling the API for listing endpoints. Constraints: N/A Range: 1 to 63 characters. Only lowercase letters, digits, and hyphens (-) are allowed. The value must start with a lowercase letter and must end with a lowercase letter or digit. Default Value: N/A |
| catalog_context | Yes | SparkSqlCatalogContext object | Definition: Catalog context information, used to specify the data catalog and database used by the job. Constraints: N/A |
| statement | Yes | String | Definition: User SQL statement, used to execute the SparkSql job. Multiple SQL types are supported, including DDL, DCL, DQL, and DML. Constraints: N/A Range: The value can contain a maximum of 500,000 characters, with no character type restrictions. Default Value: N/A |
| parameters | No | Array of SparkSqlParameter objects | Definition: List of placeholder parameters in the user SQL statement, used for parameterized SQL execution. Each element in the array is a SparkSqlParameter object, which contains the key, value, and type information of the placeholder. Constraints: The number of placeholder parameters cannot exceed 16. |
| spark_config | No | Map<String,String> | Definition: User-defined Spark parameter configuration, used to optimize job performance. The format is key/value pairs, where Key is the parameter name and Value is the parameter value. Example: spark.executor.memory=4g. Constraints: The number of parameter configuration items cannot exceed 100, and the length of each parameter value cannot exceed 1,024 characters. |
| timeout | No | SparkSqlTimeout object | Definition: Job timeout configuration, used to set the timeout duration for job queuing and execution. Constraints: N/A |
| labels | No | Array of SparkSqlLabel objects | Definition: Job tag list, used to identify and categorize jobs. Each element in the array is a SparkSqlLabel object, which contains the key and value of a tag. Constraints: The number of tags cannot exceed 16. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| catalog_name | Yes | String | Definition: Catalog name, used to specify the data catalog used by the job. This can be viewed on the catalog management page of the console or obtained by calling the API for listing catalogs. Constraints: N/A Range: The value can contain a maximum of 128 characters, with no character type restrictions. Default Value: N/A |
| database_name | No | String | Definition: Default database name, used to specify the default database for the job. If not specified, the default database of the catalog is used. Constraints: N/A Range: The value can contain a maximum of 128 characters, with no character type restrictions. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| queued_timeout | No | Integer | Definition: Job queue timeout duration, in minutes. If the job has not started running after this time, the job will be marked as queue timeout and fail. Constraints: N/A Range: 10 to 180 minutes. Default Value: 180 |
| running_timeout | No | Integer | Definition: Job running timeout duration, in minutes. If the job has not completed after this time, the job will be canceled and marked as running timeout. Constraints: N/A Range: 10 to 720 minutes. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| key | Yes | String | Definition: Tag key, used to identify the classification dimension of the job. For example: env, project, etc. Constraints: N/A Range: The value can contain 1 to 128 characters, with no character type restrictions. Default Value: N/A |
| value | Yes | String | Definition: Tag value, used to identify the specific classification of the job. For example: production, data-analytics, etc. Constraints: N/A Range: The value can contain 1 to 512 characters, with no character type restrictions. Default Value: N/A |
Response Parameters
Status code: 201
| Parameter | Type | Description |
|---|---|---|
| statement_id | String | Definition: Job ID, used to uniquely identify this SparkSql job execution. This ID can be used to query the job status and execution results. Range: 1 to 64 characters. Only hexadecimal characters, hyphens (-), and underscores (_) are allowed. Example: 6c98db52-cac2-4ff1-9a91-b7793e95557d. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Example Requests
-
Execute a simple SQL query statement. The endpoint name is spark-endpoint-01, the catalog is hive_catalog, the database is default, the query statement is SELECT * FROM table_name LIMIT 100, the queue timeout is 180 minutes, and the running timeout is 720 minutes.
POST /v2/workspaces/{workspace_id}/spark-sqls { "endpoint_name" : "spark-endpoint-01", "catalog_context" : { "catalog_name" : "hive_catalog", "database_name" : "default" }, "statement" : "SELECT * FROM table_name LIMIT 100", "timeout" : { "queued_timeout" : 180, "running_timeout" : 720 } } -
Execute a SQL statement with placeholder parameters. The endpoint name is spark-endpoint-01, the catalog is hive_catalog, and the database is default. The query statement contains the id_param and name_param parameters. The tags are env=production and project=data-analytics. The Spark configuration is as follows: executor memory: 4 GB, number of executor cores: 2, queue timeout: 180 minutes, and running timeout: 720 minutes.
POST /v2/workspaces/{workspace_id}/spark-sqls { "endpoint_name" : "spark-endpoint-01", "catalog_context" : { "catalog_name" : "hive_catalog", "database_name" : "default" }, "statement" : "SELECT * FROM table_name WHERE id = :id_param AND name = :name_param", "parameters" : [ { "key" : "id_param", "value" : "12345", "value_type" : "INTEGER" }, { "key" : "name_param", "value" : "test_table", "value_type" : "STRING" } ], "labels" : [ { "key" : "env", "value" : "production" }, { "key" : "project", "value" : "data-analytics" } ], "spark_config" : { "spark.executor.memory" : "4g", "spark.executor.cores" : "2" }, "timeout" : { "queued_timeout" : 180, "running_timeout" : 720 } } -
Execute a DDL statement to create a table. The endpoint name is spark-endpoint-01, the catalog is hive_catalog, the database is default, the CREATE TABLE statement is CREATE TABLE IF NOT EXISTS test_table (id INT, name STRING, age INT) USING PARQUET, the queuing timeout is 180 minutes, and the running timeout is 720 minutes.
POST /v2/workspaces/{workspace_id}/spark-sqls { "endpoint_name" : "spark-endpoint-01", "catalog_context" : { "catalog_name" : "hive_catalog", "database_name" : "default" }, "statement" : "CREATE TABLE IF NOT EXISTS test_table (id INT, name STRING, age INT) USING PARQUET", "timeout" : { "queued_timeout" : 180, "running_timeout" : 720 } }
Example Responses
Status code: 201
{
"statement_id" : "6c98db52-cac2-4ff1-9a91-b7793e95557d"
} Status code: 400
{
"error_code" : "AIDataLake.01011001",
"error_msg" : "Invalid parameter statement",
"solution_msg" : "Please check the input parameters according to the documentation(statement for spark sql)."
} Status code: 401
{
"error_code" : "AIDataLake.01011003",
"error_msg" : "auth token not exists in header",
"solution_msg" : "Please check if auth token is included in the request header."
} Status code: 403
{
"error_code" : "AIDataLake.01011005",
"error_msg" : "current account has no permission",
"solution_msg" : "Please connect administrators to add permission."
} Status code: 500
{
"error_code" : "AIDataLake.01010001",
"error_msg" : "Internal system error",
"solution_msg" : "Contact operations for analysis."
} Status Codes
| Status Code | Description |
|---|---|
| 201 | The operation is successful. |
| 400 | Invalid request parameter. |
| 401 | Authentication failed. |
| 403 | Insufficient permissions. |
| 500 | Internal server error. |
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