Submitting a SQL Statement
Function
This API is used to submit and execute a SQL statement in an MRS cluster.
URI
- Format
- 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 about 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
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
sql_content |
Yes |
String |
Explanation SQL statement to be executed Currently, only a single SQL statement can be executed at a time, and the statement cannot contain a semicolon (;). Constraints N/A Value range N/A Default value N/A |
database |
No |
String |
Explanation Database where the SQL statement is executed on. Constraints N/A Value range N/A Default value default |
archive_path |
No |
String |
Explanation Directory for storing the dumped SQL execution results. Only the select statement dumps query results. Currently, the query results can be dumped only to OBS. Constraints N/A Value range N/A Default value N/A |
Response Parameters
Status code: 200
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. Value range N/A |
message |
String |
Explanation Error message Value range N/A |
statement |
String |
Explanation Ongoing SQL statement Value range N/A |
status |
String |
Explanation SQL execution status Value range
|
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. Value range 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. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Explanation Error code Value range N/A |
error_msg |
String |
Explanation Error message. Value range N/A |
Example Request
Submit a Presto SQL statement.
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/sql-execution { "sql_type" : "presto", "sql_content" : "show tables", "database" : "default", "archive_path" : "obs://my-bucket/path" }
Example Response
Status code: 200
The SQL statement is submitted successfully.
{ "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 submit the SQL statement.
{ "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.
Feedback
Was this page helpful?
Provide feedbackThank 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