Updated on 2026-11-06 GMT+08:00

Establishing a Connection and Querying Data from a Specified Table

This section describes how to establish a connection to the AuraJobV2 endpoint, query data from the created table, and return the query results.

Prerequisites

Example

This example establishes a connection to the Aura service, queries text data from the text_samples table, and prints the results.

  1. Import dependencies and connect to the AuraJobV2 endpoint.
  2. Load the text_samples dataset.
  3. Select the id and content columns.
  4. Execute the query and print the results.
  5. Disable the AuraJobV2 endpoint connection.
import os
import logging
import ibis
from aura_frame.multimodal import ai_lake

target_database = "test"  #Create a database in LakeFormation, for example, test. For details, see Creating a DataArts Lake Formation Instance and Planning Metadata.
#Connect to the AuraJobV2 endpoint. For details about the parameters, see Establishing a Connection with the AuraJobV2 Endpoint.
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=target_database,                       # LakeFormation database name
    use_single_cn_mode=True,   # Whether to enable the single-CN mode
    logging_level=logging.INFO # Set the log level.
)
try:
    ds = con.load_dataset("text_samples", database=target_database)
    ds = ds.select_columns([ds.id, ds.content])
    df = ds.execute()
    print(df)
finally:
    con.close()