Updated on 2024-12-10 GMT+08:00

Querying SQL Results

Function

This API is used to query the execution result of a SQL statement in an MRS cluster.

Constraints

None

Debugging

You can debug this API in API Explorer. Automatic authentication is supported. API Explorer can automatically generate sample SDK code and provide the sample SDK code debugging.

URI

  • Format

    GET /v2/{project_id}/clusters/{cluster_id}/sql-execution/{sql_id}

  • Parameter description
    Table 1 URI parameters

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Explanation

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

    Constraints

    N/A

    Value range

    The value must consist of 1 to 64 characters. Only letters and digits are allowed.

    Default value

    N/A

    cluster_id

    Yes

    String

    Explanation

    Cluster ID. If this parameter is specified, the latest metadata of the cluster that has been patched will be obtained. For details on how to obtain the cluster ID, see Obtaining a Cluster ID.

    Constraints

    N/A

    Value range

    The value can contain 1 to 64 characters, including only letters, digits, underscores (_), and hyphens (-).

    Default value

    N/A

    sql_id

    Yes

    String

    Explanation

    The execution ID of a SQL statement, that is, sql_id in the return result in Submitting a SQL Statement.

    Constraints

    N/A

    Value range

    N/A

    Default value

    N/A

Request Parameters

None

Response Parameters

Status code: 200

Table 2 Response parameters

Parameter

Type

Description

id

String

Explanation

SQL execution ID. The ID is generated only when the SELECT, SHOW, or DESC statement is executed. For other operations, the ID is empty.

Constraints

N/A

Value range

N/A

Default value

N/A

message

String

Explanation

Error message

Constraints

N/A

Value range

N/A

Default value

N/A

statement

String

Explanation

Ongoing SQL statement

Constraints

N/A

Value range

N/A

Default value

N/A

status

String

Explanation

SQL execution status

Constraints

N/A

Value range

  • QUEUED: queuing
  • WAITING_FOR_RESOURCES: waiting for resources
  • PLANNING: being planning
  • STARTING: being started
  • RUNNING: running
  • FINISHING: to be completed
  • FINISHED: completed
  • FAILED: execution failed

Default value

N/A

result_location

String

Explanation

Path for archiving the final results of the SQL query statement Only the SELECT statement dumps the SQL execution results to result_location.

Constraints

N/A

Value range

N/A

Default value

N/A

content

Array<Array<String>>

Explanation

SQL execution result Only non-SELECT statements return results in content. If the SQL statement does not return results, content is empty.

Constraints

N/A

Value range

N/A

Default value

N/A

Status code: 400

Table 3 Response body parameters

Parameter

Type

Description

error_code

String

Explanation

Error code

Constraints

N/A

Value range

N/A

Default value

N/A

error_msg

String

Explanation

Error message.

Constraints

N/A

Value range

N/A

Default value

N/A

Example Request

Example request for querying the SQL execution result

GET https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/sql-execution/{sql_id}

Example Response

Status code: 200

Querying the SQL execution result is successful.

{
  "id" : "20190909_011820_00151_xxxxx",
  "statement" : "show tables",
  "status" : "FINISHED",
  "result_location" : "obs://my_bucket/uuid_date/xxxx.csv",
  "content" : [ [ "t1", null ], [ null, "t2" ], [ null, "t3" ] ]
}

Status code: 400

Failed to query the SQL execution result.

{
  "error_code" : "MRS.0011",
  "message": "Failed to submit SQL to the executor. The cluster ID is xxxx"
}

Status Codes

See Status Codes.

Error Codes

See Error Codes.