Below is a visual representation of how data flows through our integrated tools in this Quickstart. This comes from Dagster's global asset lineage view:
- Prerequisites
- Setting an environment for your project
- Setting Up BigQuery to work with Airbyte and dbt
- Setting Up Airbyte Connectors
- Setting Up the dbt Project
- Orchestrating with Dagster
- Next Steps
Before you embark on this integration, ensure you have the following set up and ready:
-
Python 3.10 or later: If not installed, download and install it from Python's official website.
-
Docker and Docker Compose (Docker Desktop): Install Docker following the official documentation for your specific OS.
-
Airbyte OSS version: Deploy the open-source version of Airbyte locally. Follow the installation instructions from the Airbyte Documentation.
-
Terraform (Optional): Terraform will help you provision and manage the Airbyte resources. If you haven't installed it, follow the official Terraform installation guide. This is an optional step because you can also create and manage Airbyte resources via the UI.
-
Google Cloud account with BigQuery: You will also need to add the necessary permissions to allow Airbyte and dbt to access the data in BigQuery. A step-by-step guide is provided below.
Get the project up and running on your local machine by following these steps:
-
Clone the repository (Clone only this quickstart):
git clone --filter=blob:none --sparse https://github.com/airbytehq/quickstarts.git
cd quickstarts
git sparse-checkout add ecommerce_analytics_bigquery
-
Navigate to the directory:
cd ecommerce_analytics_bigquery
At this point you can view the code in your preferred IDE. For example, if you’re using Visual Studio Code, you can execute code .
to open the code.
-
Set Up a Virtual Environment:
You can use the following commands, just make sure to adapt to your specific python installation.-
For Linux and Mac:
python3 -m venv venv source venv/bin/activate
-
For Windows:
python -m venv venv .\venv\Scripts\activate
-
-
Install Dependencies:
pip install -e ".[dev]"
- If you have a Google Cloud project, you can skip this step.
- Go to the Google Cloud Console.
- Click on the "Select a project" dropdown at the top right and select "New Project".
- Give your project a name and follow the steps to create it.
- In the Google Cloud Console, go to BigQuery.
- Make two new datasets:
raw_data
for Airbyte andtransformed_data
for dbt.- If you pick different names, remember to change the names in the code too.
How to create a dataset:
- In the left sidebar, click on your project name.
- Click “Create Dataset”.
- Enter the dataset ID (either
raw_data
ortransformed_data
). - Click "Create Dataset".
- Go to “IAM & Admin” > “Service accounts” in the Google Cloud Console.
- Click “Create Service Account”.
- Name your service account (like
airbyte-service-account
). - Assign the “BigQuery Data Editor” and “BigQuery Job User” roles to the service account.
- Follow the same steps to make another service account for dbt (like
dbt-service-account
) and assign the roles.
How to create a service account and assign roles:
- While creating the service account, under the “Grant this service account access to project” section, click the “Role” dropdown.
- Choose the “BigQuery Data Editor” and “BigQuery Job User” roles.
- Finish the creation process.
- For both service accounts, make a JSON key to let the service accounts sign in.
How to generate JSON key:
- Find the service account in the “Service accounts” list.
- Click on the service account name.
- In the “Keys” section, click “Add Key” and pick JSON.
- The key will download automatically. Keep it safe and don’t share it.
- Do this for the other service account too.
To set up your Airbyte connectors, you can choose to do it via Terraform, or the UI. Choose one of the two following options.
Airbyte allows you to create connectors for sources and destinations via Terraform, facilitating data synchronization between various platforms. Here's how you can set this up:
-
Navigate to the Airbyte Configuration Directory:
cd infra/airbyte
-
Modify Configuration Files:
Within the
infra/airbyte
directory, you'll find three crucial Terraform files:provider.tf
: Defines the Airbyte provider.main.tf
: Contains the main configuration for creating Airbyte resources.variables.tf
: Holds various variables, including credentials.
Adjust the configurations in these files to suit your project's needs:
-
Provide credentials for your BigQuery connection in the
main.tf
file.dataset_id
: The name of the BigQuery dataset where Airbyte will load data. In this case, enter “raw_data”.project_id
: Your BigQuery project ID.credentials_json
: The contents of the service account JSON file. You should input a string, so you need to convert the JSON content to string beforehand.workspace_id
: Your Airbyte workspace ID, which can be found in the webapp url. For example, in this url: http://localhost:8000/workspaces/910ab70f-0a67-4d25-a983-999e99e1e395/ the workspace id would be910ab70f-0a67-4d25-a983-999e99e1e395
.
-
Alternatively, you can utilize the
variables.tf
file to manage these credentials:- You’ll be prompted to enter the credentials when you execute
terraform plan
andterraform apply
. If going for this option, just move to the next step. If you don’t want to use variables, remove them from the file.
- You’ll be prompted to enter the credentials when you execute
-
Initialize Terraform:
This step prepares Terraform to create the resources defined in your configuration files.
terraform init
-
Review the Plan:
Before applying any changes, review the plan to understand what Terraform will do.
terraform plan
-
Apply Configuration:
After reviewing and confirming the plan, apply the Terraform configurations to create the necessary Airbyte resources.
terraform apply
-
Verify in Airbyte UI:
Once Terraform completes its tasks, navigate to the Airbyte UI. Here, you should see your source and destination connectors, as well as the connection between them, set up and ready to go 🎉.
Start by launching the Airbyte UI by going to http://localhost:8000/ in your browser. Then:
-
Create a source:
- Go to the Sources tab and click on
+ New source
. - Search for “faker” using the search bar and select
Sample Data (Faker)
. - Adjust the Count and optional fields as needed for your use case. You can also leave as is.
- Click on
Set up source
.
- Go to the Sources tab and click on
-
Create a destination:
- Go to the Destinations tab and click on
+ New destination
. - Search for “bigquery” using the search bar and select
BigQuery
. - Enter the connection details as needed.
- For simplicity, you can use
Standard Inserts
as the loading method. - In the
Service Account Key JSON
field, enter the contents of the JSON file. Yes, the full JSON. - Click on
Set up destination
.
- Go to the Destinations tab and click on
-
Create a connection:
- Go to the Connections tab and click on
+ New connection
. - Select the source and destination you just created.
- Enter the connection details as needed.
- Click on
Set up connection
.
- Go to the Connections tab and click on
That’s it! Your connection is set up and ready to go! 🎉
dbt (data build tool) allows you to transform your data by writing, documenting, and executing SQL workflows. Setting up the dbt project requires specifying connection details for your data platform, in this case, BigQuery. Here’s a step-by-step guide to help you set this up:
-
Navigate to the dbt Project Directory:
Move to the directory containing the dbt configuration:
cd ../../dbt_project
-
Update Connection Details:
- You'll find a
profiles.yml
file within the directory. This file contains configurations for dbt to connect with your data platform. Update this file with your BigQuery connection details. Specifically, you need to update the Service Account JSON file path and your BigQuery project ID. - Provide your BigQuery project ID in the
database
field of thedbt_project/models/sources/faker_sources.yml
file.
- You'll find a
If you want to avoid hardcoding credentials in the profiles.yml
file, you can leverage environment variables. An example of how to use them in this file is provided for the keyfile
key.
-
Test the Connection:
Once you’ve updated the connection details, you can test the connection to your BigQuery instance using:
dbt debug
If everything is set up correctly, this command should report a successful connection to BigQuery 🎉.
Dagster is a modern data orchestrator designed to help you build, test, and monitor your data workflows. In this section, we'll walk you through setting up Dagster to oversee both the Airbyte and dbt workflows:
-
Navigate to the Orchestration Directory:
Switch to the directory containing the Dagster orchestration configurations:
cd ../orchestration
-
Set Environment Variables:
Dagster requires certain environment variables to be set to interact with other tools like dbt and Airbyte. Set the following variables:
export DAGSTER_DBT_PARSE_PROJECT_ON_LOAD=1 export AIRBYTE_PASSWORD=password
Note: The
AIRBYTE_PASSWORD
is set topassword
as a default for local Airbyte instances. If you've changed this during your Airbyte setup, ensure you use the appropriate password here. -
Launch the Dagster UI:
With the environment variables in place, kick-start the Dagster UI:
dagster dev
-
Access Dagster in Your Browser:
Open your browser and navigate to:
http://127.0.0.1:3000
Here, you should see assets for both Airbyte and dbt. To get an overview of how these assets interrelate, click on view global asset lineage
at the top right corner of the Dagster UI. This will give you a clear picture of the data lineage, visualizing how data flows between the tools.
-
Materialize Dagster Assets:
In the Dagster UI, click on
Materialize all
. This should trigger the full pipeline. First the Airbyte sync to extract data from Faker and load it into BigQuery, and then dbt to transform the raw data, materializing thestaging
andmarts
models.
You can go to the Airbyte UI and confirm a sync is running, and then, once the dbt jobs have run, go to your BigQuery console and check the views have been created in the transformed data
dataset.
Congratulations on deploying and running the E-commerce Analytics Quistart! 🎉 Here are some suggestions on what you can explore next to dive deeper and get more out of your project:
- Dive into the datasets in BigQuery, run some queries, and explore the data you've collected and transformed. This is your chance to uncover insights and understand the data better!
- Review the transformations you’ve applied using dbt. Try optimizing the models or create new ones based on your evolving needs and insights you want to extract.
- Add more data sources to Airbyte. Explore different types of sources available, and see how they can enrich your existing datasets and broaden your analytical capabilities.
- Implement data quality tests in dbt to ensure the reliability and accuracy of your transformations. Use dbt's testing features to validate your data and catch issues early on.
- Explore more advanced Dagster configurations and setups to automate your pipelines further and set up monitoring and alerting to be informed of any issues immediately.
- Consider scaling your setup to handle more data, more sources, and more transformations. Optimize your configurations and resources to ensure smooth and efficient processing of larger datasets.
- Share your learnings, optimizations, and new configurations with the community. Contribute to the respective tool’s communities and help others learn and grow.