In this lab module, we will learn to automate the process of Data Quality validation followed by Data Quality Scores tagging. Both these elements were completed individually in prior modules. In this module, we will orchestrate the sequential execution.
Successful completion of prior modules
15 minutes or less
Data Quality Task orchestration with Airflow
Userstand how to automate Data Quality tasks with Apache Airflow on Cloud Composer. This includes polling for completion of async Dataplex tasks.
We need to import "requests_oauth2" Python package. Let us update the Cloud Composer environment to add the package. We will first create a requirements.txt file and then update the Cloud Composer environment with it.
# Variables
PROJECT_ID=`gcloud config list --format "value(core.project)" 2>/dev/null`
PROJECT_NBR=`gcloud projects describe $PROJECT_ID | grep projectNumber | cut -d':' -f2 | tr -d "'" | xargs`
UMSA_FQN="lab-sa@${PROJECT_ID}.iam.gserviceaccount.com"
LOCATION="us-central1"
COMPOSER_ENVIRONMENT_NAME="oda-$PROJECT_NBR-cc2"
# Create requirements.txt with desired package to be installed
cd ~/tmp/dataplex-quickstart-labs/dq
rm -rf requirements.txt
cat <<EOF >>requirements.txt
requests_oauth2
EOF
# Update environment to install package from PyPi GCS mirror
gcloud composer environments update $COMPOSER_ENVIRONMENT_NAME \
--location $LOCATION \
--update-pypi-packages-from-file requirements.txt
This takes ~10 minutes.
This is the DAG we will use in the lab-
The DAG code is available in your cloud shell already and is called customer_master_dq_automation_primer.py
cat ~/dataplex-quickstart-labs/00-resources/scripts/airflow/data-quality/customer_master_dq_automation_primer.py
Study the code and understand the construct - for the task submission as well as polling.
Lets upload the DAG to the Cloud Composer DAG bucket.
PROJECT_ID=`gcloud config list --format "value(core.project)" 2>/dev/null`
PROJECT_NBR=`gcloud projects describe $PROJECT_ID | grep projectNumber | cut -d':' -f2 | tr -d "'" | xargs`
LOCATION="us-central1"
# DAG bucket to upload to
DAG_BUCKET=`gcloud composer environments describe oda-$PROJECT_NBR-cc2 --location $LOCATION | grep dagGcsPrefix: | cut -d' ' -f4`
# Upload the DAG
gsutil cp ~/dataplex-quickstart-labs/00-resources/scripts/airflow/data-quality/customer_master_dq_automation_primer.py $DAG_BUCKET/data-quality/
Follow the screenshots to run the DAG-
Click on the task link to see the execution in Dataproc Serverless batches.
This takes about 2.5 minutes to complete.
This takes about 2.5 minutes to complete.
Run the below in BigQuery-
SELECT * FROM `oda_dq_scratch_ds.dq_results_iteration_1`
This concludes the lab module. Proceed to the next module.














