Submitting an SQL Statement
Function
This API is used to submit and execute an SQL statement in an MRS cluster.
URI
- Format
- Parameter description
Table 1 URI parameter description Parameter
Mandatory
Description
project_id
Yes
Project ID. For details on how to obtain the project ID, see Obtaining a Project ID.
cluster_id
Yes
Cluster ID. For details on how to obtain the cluster ID, see Obtaining a Cluster ID.
Request
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
sql_type |
Yes |
String |
SQL type. Currently, only the SQL of the presto type is supported.
NOTE:
The SQL of the presto type can be submitted and executed only in clusters containing the Presto component. |
sql_content |
Yes |
String |
SQL statement to be executed
NOTE:
Currently, only a single SQL statement can be executed at a time, and the statement cannot contain a semicolon (;). |
database |
No |
String |
Database where the SQL statement to be executed resides. The default value is default. |
archive_path |
No |
String |
Directory for storing the dumped SQL execution results.
NOTE:
Only the select statement dumps query results. Currently, the query results can be dumped only to OBS. |
Response
Parameter |
Type |
Description |
---|---|---|
id |
String |
SQL ID |
message |
String |
Error message |
statement |
String |
Executed SQL statement |
status |
String |
SQL execution status
|
result_location |
String |
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 |
SQL execution result
NOTE:
Only non-select statements return results in content. If the SQL statement does not return results, content is empty. |
Example
- Example request
{ "sql_type":"presto", "sql_content":"show tables", "database":"default", "archive_path":"obs://my-bucket/path" }
- 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":[ ["t1"],["t2"],["t3"] ] }
- Example of a failed response
{ "error_code" : "MRS.0011", "message": "Failed to submit SQL to the executor. The cluster ID is xxxx" }
- Example of a successful response
Status Code
For details about status codes, see Status 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