Help Center/ AI DataLake/ SDK Reference/ Engine-specific SDKs/ Python SDKs/ Spark SDK (Python)/ Submitting a Spark SQL Job
Updated on 2026-11-06 GMT+08:00
Submitting a Spark SQL Job
Description
This section describes how to submit a SQL job using AI DataLake SDK.
Prerequisites
- The Python SDK environment has been configured and initialized. For details, see Obtaining and Initializing the Spark SDK.
- Permissions related to APIs and SQL jobs have been configured. For details, see Permissions and Supported Actions.
- The compute resources and endpoints in use are available.
Functions
AidatalakeClient
# Synchronous submission function execute_sql(); # Asynchronous submission function async_execute_sql();
Sample Code
- Asynchronous SQL submission
try: sql_job = client.async_execute_sql( "SELECT 1 AS value", database_name="database_name", endpoint_name="endpoint_name", catalog="catalog_name", ) logger.info("Job submitted. Statement ID: %s", sql_job.job_id) # Poll for completion status, msg = sql_job.get_status() logger.info("Initial status: %s", status) except Exception as e: logger.error("Example 2 FAILED: %s", e)
- Synchronous SQL submission
try: sql_job = client.execute_sql( "SHOW DATABASES", database_name="database_name", endpoint_name="endpoint_name", catalog="catalog_name", ) logger.info("Job completed. ID: %s, Status: %s", sql_job.job_id, sql_job.job_status) except Exception as e: logger.error("Example 1 FAILED: %s", e)
- SQL query
try: job = client.new_sql_job_builder("SELECT * FROM demo_db1.demo_tbl1 LIMIT 10") \ .catalog_name(catalog_name) \ .database_name(database_name) \ .labels([{"key": "env", "value": "dev"}]) \ .running_timeout(300) \ .queue_timeout(60) \ .job_timeout(600) \ .build() # Submit and wait job.submit() logger.info("Job completed. ID: %s", job.job_id) result = job.get_result() if result: row_count = sum(1 for _ in result) logger.info("Rows: %d", row_count) if hasattr(result, 'close'): result.close() except Exception as e: logger.error("Example 3 FAILED: %s", e)
Parameters
| Parameter | Mandatory (Yes/No) | Default Value | Description |
|---|---|---|---|
| database_name | Yes | None | Default LakeFormation database name. |
| endpoint_name | Yes | None | SparkSQL endpoint name. |
| catalog | Yes | None | Default LakeFormation catalog name. |
Parent topic: Spark SDK (Python)
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
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.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot