Updated on 2022-11-18 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 through automatic authentication in API Explorer. 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

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

    cluster_id

    Yes

    String

    Cluster ID. For details on how to obtain the cluster ID, see Obtaining a Cluster ID.

    sql_id

    Yes

    String

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

Request Parameters

Request parameters

None

Response Parameters

Status code: 200

Table 2 Response parameters

Parameter

Type

Description

id

String

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

message

String

The error message.

statement

String

The SQL statement to be executed.

status

String

The execution status of a SQL statement. Possible values:

  • QUEUED
  • WAITING_FOR_RESOURCES
  • PLANNING
  • STARTING
  • RUNNING
  • FINISHING
  • FINISHED
  • FAILED

result_location

String

The path for archiving the final results of the SQL query statement.

NOTE:

Only the SELECT statement dumps the SQL execution results to result_location.

content

Array

The execution result of the SQL statement.

NOTE:

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

Status code: 400

Table 3 Response body parameters

Parameter

Type

Description

error_code

String

The error code.

error_msg

String

The error message.

Example

  • Example request
    GET https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/sql-execution/{sql_id}
  • Example response
    • Example of a successful response
      {
          "id":"20190909_011820_00151_xxxxx ", 
          "statement":"show tables",
          "status":"FINISHED",
          "result_location":" obs://my_bucket/uuid_date/xxxx.csv",  
          "content": [ null, "t1", null, "t2", null, "t3" ]
       }
    • Example of a failed response
      { 
        "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.