Getting Started with the Aura DataFrame SDK
This section describes the complete workflow of developing data applications using the Aura DataFrame SDK.
Workflow Overview
| Step | Operation | Description |
|---|---|---|
| Obtain and install the SDK installation package. | Install the Aura DataFrame SDK package. | |
| Establish a connection. | Use ai_lake.connect() to create a session. Before using UDFs, configure and deploy a workspace. | |
| Prepare data. | Load an existing dataset, create a data table, and write data. | |
| Process data. | Use DataFrame APIs to perform operations such as filtering, aggregation, sorting, and joining. | |
| Perform advanced data development operations. | Use UDFs and multi-modal processing capabilities based on service requirements. | |
| View the job execution results. | Check whether the job is running as expected and close the session to release resources. |
Step 1: Obtain And Install The Sdk Installation Package.
pip install huawei_aura_connectorapi-x.x.x-py3-none-any.whl pip install huawei_aura_frame-x.x.x.x-py3-none-any.whl
x.x.x.x and x.x.x indicate the version numbers. Replace them with the actual ones. For details, see Obtaining and Installing the Aura DataFrame SDK.
Step 2: Establish a Connection.
Use ai_lake.connect() to create a session connection to the Aura endpoint. Before using UDFs, you need to configure and deploy a workspace.
For details, see Establishing a Connection with the AuraJobV2 Endpoint.
Create a session and configure connection information (endpoint, workspace ID, catalog, AK/SK, and database).
import os
import logging
from aura_frame.multimodal import ai_lake
con = ai_lake.connect(
aura_endpoint=os.getenv("aura_endpoint"), # Endpoint where the AuraJobV2 endpoint is located
aura_endpoint_id=os.getenv ("aura_endpoint_id"), # AuraJobV2 endpoint ID
aura_endpoint_name=os.getenv("aura_endpoint_name"), # AuraJobV2 endpoint name
aura_workspace_id=os.getenv("aura_workspace_id"), # Workspace ID
lf_catalog_name=os.getenv ("lf_catalog_name"), # LakeFormation Catalog name
access_key=os.getenv("access_key"), # Access Key ID (AK)
secret_key=os.getenv("secret_key"), # Secret Key (SK)
default_database="postgres", # Default database
use_single_cn_mode=True, # Whether to enable the single-CN mode
logging_level=logging.INFO, # Set the log level.
) Step 3: Prepare Data.
Create a data table, write data, and load an existing dataset.
- Create a table and data.
- Create a database in LakeFormation, for example, database1. For details, see Creating a LakeFormation Instance and Planning Metadata.
- Create a data table (if the target table does not exist in the database). In the create_table statement, you can use the store parameter to specify the table format (such as ORC, PARQUET, or ICEBERG) and the partition_by parameter to specify the partition column.
import ibis table_name = "table_name" table_schema = ibis.schema({"col_a": "int32", "col_b": "string"}) con.sql(f'DROP TABLE IF EXISTS database1."{table_name}";') con.create_table( table_name, schema=table_schema, database="database1", table_format="orc", if_not_exists=True, ) - Run the SQL statement to write data.
con.sql("INSERT INTO database1.table_name VALUES(1, 's1'), (2, 's2')")For details, see Creating a Table and Writing Data to the Table.
- Load an existing dataset.
ds = con.load_dataset("table_name", database="database1") # Load a table from the specified database and create a table object. Replace table_name and database1 with the actual table name and database name.
Step 4: Process Data.
Use DataFrame APIs to perform operations such as filtering, aggregation, sorting, and joining on data.
DataFrame operations use the lazy loading mechanism. The following operations only record the calculation intent. The Aura engine executes the operations and returns the Pandas DataFrame only when execute() is called.
For details, see Data Processing and Analysis.
# Select columns.
ds=ds.select_columns([ds.col_a, ds.col_b])
# Filter rows.
ds=ds.filter(ds.col_a > 0)
# Group and aggregate (aggregate the numeric column col_a).
ds=ds.groupby("col_a").aggregate(sum_b=ds.col_a.sum(), avg_b=ds.col_a.mean())
# Sort.
ds=ds.order_by(ds.col_a.desc())
# Trigger execution and return the Pandas DataFrame (key step).
df=ds.execute()
print(df) Step 5: Perform Advanced Data Development Operations.
Use UDFs and multi-modal processing capabilities based on service requirements.
- For details about how to register and use scalar UDFs, class UDFs, and UDAFs, see Using Scalar UDFs to Process Data, Using Class UDFs to Process Data and Using UDAFs for Aggregation Statistics.
- For details about UDF types, registration methods, and development standards, see UDFs.
Step 6: View the Job Execution Results.
After the job runs successfully, the run logs display the execution process and results (such as table creation, SQL execution, and query result return). You can check whether the job is running as expected based on these logs.
For more examples, see Submitting a Job Using the Aura DataFrame SDK.
After the data operation is complete, close the session to release resources.
con.close() # Close the session and release resources.
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