Help Center/ AI DataLake/ SDK Reference/ Engine-specific SDKs/ Python SDKs/ Catalog SDK/ Running the Example with AuraJobV2
Updated on 2026-11-06 GMT+08:00
Running the Example with AuraJobV2
This example demonstrates how to register a UDF with LakeFormation using the SDK, and then use the AuraJobV2 engine to read data columns from a specified database table and perform calculations using the UDF.
Prerequisites
- An OBS parallel file system has been created to store the UDF package uploaded by the SDK. For details, see Creating a Parallel File System.
- A LakeFormation instance has been created, with a catalog and a database available in the instance. For details, see Creating a DataArts Lake Formation Instance and Planning Metadata.
- A data table has been registered in LakeFormation. (In this example, the table contains at least the id and value columns.)
- An AuraJobV2 endpoint has been created, and information such as the endpoint name and workspace ID has been obtained. For details, see Creating an Aura Engine Endpoint.
- You have obtained the AK/SK information and have the permission to access the OBS parallel file system and LakeFormation.
- The Aura DataFrame SDK has been obtained and installed. For details, see Obtaining and Installing the Aura DataFrame SDK.
Example
# 1. Import dependencies.
import os
from aidatalake_catalog import Parameter, Signature
from aidatalake_catalog.client import AIDatalake_Catalog_Client
from aura_frame.multimodal import ai_lake
# 2. Define a UDF with type annotations.
class Multiplier:
"""Class-defined UDF: Multiplies by a configurable factor (default: 2)."""
def __init__(self, factor: int = 2):
self._factor = factor
def __call__(self, x: int) -> int:
return x * self._factor
# 3. Define the function signature. (Optional. If not passed, the SDK automatically infers it based on the type annotations.)
sig = Signature(
parameters=[Parameter(name="x", annotation=int)],
return_annotation=int,
)
# 4. Initialize the Catalog client. (You are advised to read the AK/SK from environment variables to avoid hardcoding.)
client = AIDatalake_Catalog_Client(
ak=os.getenv("XXX_SDK_AK"),
sk=os.getenv("XXX_SDK_SK"),
security_token=None, # Used for temporary credentials
obs_endpoint="obs.cn-north-4.myhuaweicloud.com",
lakeformation_endpoint="https://lakeformation.cn-north-4.myhuaweicloud.com",
lakeformation_instanceid="your-instance-id",
catalog_name="your-catalog-name",
default_database="your_default_db",
obs_path="your-bucket/udf/", # bucket_name/dir/subdir
project_id="your-project-id",
ignore_ssl_verification=False,
)
# 5. Register the UDF.
func = client.create_udf(
Multiplier,
name="class_multiplier_def",
signature=sig,
description="Class-defined UDF: Multiplies by a factor (default: 2)."
)
# 6. Use the Aura engine to execute the function.
"""
| id | value|
|------|------|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
"""
con = ai_lake.connect(
aura_endpoint=os.getenv("aura_endpoint"),
aura_endpoint_name=os.getenv("aura_endpoint_name"),
aura_workspace_id=os.getenv("aura_workspace_id"),
lf_catalog_name=os.getenv("lf_catalog_name"),
access_key=os.getenv("access_key"),
secret_key=os.getenv("secret_key"),
default_database=target_database,
use_single_cn_mode=True
)
ds = con.load_dataset("table_1") # table_1 must be registered with LakeFormation in advance.
ds = ds.map(fn=f'{database}.class_multiplier_def', on=['value'], as_col='mul_result')
df = ds.execute().sort_values('id').reset_index(drop=True)
print(f" {'ID':<5} {'Original value':<10} {'mul_result':<15}")
print("-" * 35)
for _, r in df.iterrows():
print(f"{int(r['id']):<5} {int(r['value']):<10} {int(r['mul_result']):<15}") Execution result:
ID Original value mul_result ----------------------------------- 1 10 20 2 20 40 3 30 60
Parent topic: Catalog SDK
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