Using the AuraSQL API
Overview
This section describes the complete process of using an AuraSQL job by calling APIs, including creating a session, executing SQL statements, viewing SQL execution results, and closing the session.
This process assumes that the end tenant has been authorized on the console to use AI DataLake and has created a workspace and a session endpoint. For how to call this API, see Calling an API.
Prerequisites
- An Aura endpoint has been created and is in the Running state.
- The address of the engine for which a session is to be created has been obtained.
- The workspace ID for which a session is to be created has been obtained.
- The endpoint name for which a session is to be created has been obtained.
- The LakeFormation catalog name for which a session is to be created has been obtained.
Creating a Session
- API information
URI format: POST /v2/workspaces/{workspace_id}/aura-sessions
For details, see Creating a Session.
- Request example
POST /v2/workspaces/{workspace_id}/aura-sessions
{workspace_id}: ID of the workspace where the endpoint is located.
Request body:{ "endpoint_name":"aura-job-vzhh", "catalog_context":{ "catalog_name": "xxx_default" } } - Response example
{ "session_id": "019ec92b-f4cc-xxxx-xxxx-C46dcdd60929", "status": "RUNNING" }
Executing a SQL Statement
- API information
URI format: POST /v2/workspaces/{workspace_id}/aura-sessions/statements
For details, see Executing SQL Statements Under a Specified Session.
- Request example
POST /v2/workspaces/{workspace_id}/aura-sessions/statements
{workspace_id}: ID of the workspace where the endpoint is located.
Request body:{ "statement":"DROP SCHEMA IF EXISTS abcdefgh CASCADE; CREATE SCHEMA abcdefgh; DROP FUNCTION IF EXISTS test_gpu; CREATE FUNCTION test_gpu(x INTEGER) RETURNS TEXT handler = 'check_gpu_simple' runtime_version = '3.11' AS $$ def check_gpu_simple(x): return "hello world" $$ LANGUAGE python;", "limit": 1, "session_id": "019ec92b-f4cc-xxxx-xxxx-C46dcdd60929", "is_sync": false } - Response example
{ "session_id": "019ec92b-f4cc-xxxx-xxxx-C46dcdd60929", "statement_id": "019eb5fb-871d-xxxx-xxxx-68534fa6f089", "status": 1 }
Viewing SQL Execution Results
- API information
URI format: GET /v2/workspaces/{workspace_id}/aura-sessions/{session_id}/statements/{statement_id}
For details, see Viewing the Execution Result of a SQL Statement.
- Request example
GET /v2/workspaces/{workspace_id}/aura-sessions/{session_id}/statements/{statement_id}
- {workspace_id} indicates the ID of the workspace where the endpoint is located.
- {session_id} indicates the session ID.
- {statement_id} indicates the task ID of the SQL execution.
- Response example
{ "status" : 0, "session_id" : "019ec92b-f4cc-xxxx-xxxx-C46dcdd60929", "statement_id" : "019eb5fb-871d-xxxx-xxxx-68534fa6f089", "results" : [ { "status" : "PGRES_TUPLES_OK", "statement_id" : "019eb5fb-871d-xxxx-xxxx-68534fa6f089", "num_rows" : 1, "row_count" : 1, "page_count" : 1, "page_no" : 1, "err_code" : "0", "sql_state" : "0", "message" : "", "result_set" : { "columns" : [ { "name" : "test_gpu", "table_id" : 0, "column_id" : 0, "format" : 0, "type" : 25, "size" : -1, "type_mod" : -1 } ], "rows" : [ [ "0000000" ] ] } } ] }
Closing a Session
- API information
URI format: DELETE /v2/workspaces/{workspace_id}/aura-sessions/{session_id}
For details, see Deleting a Session.
- Request example
DELETE /v2/workspaces/{workspace_id}/aura-sessions/{session_id}
- {workspace_id} indicates the ID of the workspace where the endpoint is located.
- {session_id} indicates the session ID.
What is your overall rating for this page?
Thank 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