Help Center/ AI DataLake/ API Reference/ Spark APIs/ SparkSql Job Management/ Previewing SparkSql Job Query Results
Updated on 2026-11-06 GMT+08:00

Previewing SparkSql Job Query Results

Function

This API is used to preview the query results of a SparkSql job. It is synchronous. It is only applicable to successfully executed DQL-type jobs. You can view the data content returned by the job. After a successful call, the query result data is returned directly. You can view job details via the API for viewing Spark SQL job details.

Calling Method

For details, see Calling APIs.

URI

POST /v2/workspaces/{workspace_id}/spark-sqls/{statement_id}/preview

Table 1 Path Parameters

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

statement_id

Yes

String

Definition: Spark SQL job ID, used to uniquely identify a SparkSql job execution. It can be obtained from the statement_id in the response of the API for executing a Spark SQL job or from the API for listing Spark SQL jobs.

Constraints: N/A

Range: 1 to 64 characters. Only hexadecimal characters, hyphens (-), and underscores (_) are allowed.

Default Value: N/A

Request Parameters

Table 2 Request header 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

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

result_format

String

Definition: Query SQL result format, used to specify the storage format of the results.

Range

  • csv: CSV format.

  • arrow: Apache Arrow format.

result_path

String

Definition: OBS path for query SQL results, used to store the result data of the SQL query.

Range: OBS path format, for example, obs://bucket/aidatalake/workspace_{workspace_id}/spark/endpoint_{endpoint_id}/jobs/sql_result/{engine_id}/{yyyy_MM_dd}/{statement_id}/result. The path is automatically generated and does not need to be constructed. {workspace_id} indicates the workspace ID, {endpoint_id} indicates the endpoint ID, {engine_id} indicates the SQL engine ID, {yyyy_MM_dd} indicates the date, and {statement_id} indicates the job ID.

schema

Array of SparkSqlSchemaItem objects

Definition: Column structure definition of the result data, containing column names and column type information. Each element in the array is a SparkSqlSchemaItem object.

rows

Array<Array<String>>

Definition: Job result set, containing the actual data rows returned by the query. Each row is an array corresponding to the column order defined in the schema.

Table 4 SparkSqlSchemaItem

Parameter

Type

Description

column_name

String

Definition: Column name, used to identify the column name in the result data.

Range: 1 to 128 characters. Example: col1.

column_type

String

Definition: Column type, used to identify the data type of the column in the result data.

Range: Spark SQL data type name. Examples: tinyint, smallint, int, bigint, float, double, decimal, string, varchar, char, boolean, binary, date, and timestamp. Complex types (array, map, struct) are returned as their Spark SQL type strings.

Status code: 400

Table 5 Response body parameters

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

Table 6 Response body parameters

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

Table 7 Response body parameters

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

Table 8 Response body parameters

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

Preview the data content returned by a successfully executed SparkSql job, used for verifying query results, data quality checks, and result display.

POST /v2/workspaces/{workspace_id}/spark-sqls/{statement_id}/preview

Example Responses

Status code: 200

{
  "result_format" : "csv",
  "result_path" : "obs://my-bucket/aidatalake/workspace_a1b2c3d4e5f6470a9c1b8d2e3f4a5b6c/spark/endpoint_9f8e7d6c5b4a39281706f5e4d3c2b1a0/jobs/sql_result/019e19fb78887b57b2f6c4174cd5a002/2026_06_01/01928d08-b98a-73ce-91df-a7a0dc984207/result",
  "schema" : [ {
    "column_name" : "id",
    "column_type" : "int"
  }, {
    "column_name" : "name",
    "column_type" : "string"
  } ],
  "rows" : [ [ "1", "test" ], [ "2", "demo" ] ]
}

Status code: 400

{
  "error_code" : "AIDataLake.01011001",
  "error_msg" : "Invalid parameter statement_id",
  "solution_msg" : "Please check the input parameters according to the documentation(statement_id 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

200

SparkSql job query results successfully previewed.

400

Invalid request parameter.

401

Authentication failed.

403

Insufficient permissions.

500

Internal server error.