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
- A table has been created and data has been written to it. For details, see Creating a Table and Writing Data to the Table.
- The Python 3.11 has been installed.
Example
This example establishes a connection to the Aura service, queries text data from the text_samples table, and prints the results.
- Import dependencies and connect to the AuraJobV2 endpoint.
- Load the text_samples dataset.
- Select the id and content columns.
- Execute the query and print the results.
- 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()
Helpful Links
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