Configuring DBT to Connect to DLI for Data Scheduling and Analysis
Data Build Tool (DBT) is an open-source data modeling and transformation tool that runs in a Python environment. By connecting DBT to DLI, you can define and execute SQL transformations and support full lifecycle data management, from integration and transformation to analytics. It is suitable for large-scale analytics projects and complex data analysis scenarios.
This section describes the steps to connect DBT to DLI.
Preparations
- Environment requirements:
Ensure your system environment meets the following requirements:
- Obtaining the dli-dbt driver package:
Download the JDBC driver huaweicloud-dli-jdbc-xxx-dependencies.jar from the DLI management console.
- Connection information:
Table 1 Connection information Item
Description
How to Obtain
DLI's AK/SK
AK/SK-based authentication uses an AK/SK pair to sign requests for identity authentication.
DLI endpoint address
Endpoint of a cloud service in a region.
DLI project ID
Project ID used for resource isolation.
DLI region information
Region to which DLI belongs.
Step 1: Deploy a DBT Environment
- Install dbt-core.
Use pip to install the recommended dbt-core version.
pip install dbt-core==1.7.9
pip is Python's package manager and is usually installed with Python.
If pip is not installed, install it using Python's built-in ensurepip module.
python -m ensurepip
- Install dli-sdk-python.
Run:
python setup.py install
- Install dli-dbt.
Download the dli-dbt driver from the DLI management console.
Run:
python setup.py install
After installation, verify DBT by running:
dbt --version
Step 2: Configure DBT to Connect to DLI
Configure the profiles.yml file to store DBT-to-DLI connection information.
In the home directory of the server where DBT is installed, locate the .dbt directory, and create or edit the profiles.yml file.
For example, on Windows, the path may be C:\Users\Username\.dbt\profiles.yml.
The configuration file should include DBT-to-DLI connection settings, for example:
profiles:
- name: dbt_dli
target: dev
outputs:
dev:
type: dli
region: your-region-name
project_id: your-project_id
access_id: your-ak
secret_key: your-sk
queue: your-queue-name
database: your-dli-database
schema: your-dli-schema | Parameter | Mandatory | Description | Example Value |
|---|---|---|---|
| type | Yes | Data source type. Set it to dli in this example. | dli |
| region | Yes | Region name. | ap-southeast-2 |
| project_id | Yes | Project ID where DLI resources are located. | 0b33ea2a7e0010802fe4c009bb05076d |
| access_id and secret_key | Yes | AK/SK credentials. | - |
| queue | Yes | DLI queue name. | dli_test |
| database | Yes | Data directory name, with dli as default. If using LakeFormation metadata, specify the exact catalog name. | dli |
| schema | Yes | DLI database name used to submit jobs. | tpch |
Step 3: Test Submitting Jobs to DLI with DBT
- Initialize a DBT project.
Run the following command in an empty directory:
dbt init
- Configure dbt_project.yml.
In the project root directory, create or edit the dbt_project.yml file.
Configure the project by referring to dbt_project.yml.
Ensure that the data source name defined in profiles.yml of the project has been set in the profile file in Step 2: Connect DBT to DLI.
Figure 1 profile file
Figure 2 profile configured in the dbt_project.yml file
- Verify the configuration.
Run the following command to check whether the DBT configuration is correct:
dbt debug
- Run project jobs. After verification succeeds, run the following command to execute your data models:
dbt run
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