Dataflow is a Google Cloud service that provides unified stream and batch data processing at scale. It is built on the Apache Beam project, which is an open source model for defining both batch and streaming data-parallel processing pipelines. Using one of the open source Apache Beam SDKs, you can build a program that defines the pipeline and then use Dataflow to execute the pipeline.
In this lab, you use the Apache Beam SDK for Python to build and run a pipeline in Dataflow to ingest data from Cloud Storage to BigQuery, and then transform and enrich the data in BigQuery.
Note: Be sure to open the Python files and read the comments when instructed. This provides an understanding of what the code does.
What you'll do
In this lab, you learn how to:
Build and run Dataflow pipelines (Python) to ingest data from Cloud Storage to BigQuery.
Build and run Dataflow pipelines (Python) to transform and enrich data in BigQuery.
Build and run Dataflow pipelines (Python) to join data in BigQuery and write the results to a new table.
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
How to start your lab and sign in to the Google Cloud console
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method.
On the left is the Lab Details pane with the following:
The Open Google Cloud console button
Time remaining
The temporary credentials that you must use for this lab
Other information, if needed, to step through this lab
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account.
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}}
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}}
You can also find the Password in the Lab Details pane.
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
Note: Using your own Google Cloud account for this lab may incur extra charges.
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
Continue through the Cloud Shell information window.
Authorize Cloud Shell to use your credentials to make Google Cloud API calls.
When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:
Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
(Optional) You can list the active account name with this command:
gcloud auth list
Click Authorize.
Output:
ACTIVE: *
ACCOUNT: {{{user_0.username | "ACCOUNT"}}}
To set the active account, run:
$ gcloud config set account `ACCOUNT`
(Optional) You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = {{{project_0.project_id | "PROJECT_ID"}}}
Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Ensure that the Dataflow API is successfully enabled
To ensure access to the necessary API, restart the connection to the Dataflow API.
Important: Even if the API is currently enabled, follow steps 1-4 below to disable, and then re-enable the API, to restart the API successfully.
In the Google Cloud console title bar, type Dataflow API in the Search field and then click Dataflow API from the search results.
Click Manage.
Click Disable API.
If asked to confirm, click Disable.
Click Enable.
When the API has been re-enabled, the page shows the Disable option.
Click Check my progress to verify your performed task.
Disable and re-enable the Dataflow API.
Task 2. Download the starter code
Download the Dataflow Python examples to use in this lab.
Click Check my progress to verify your performed task.
Copy Files to Your Bucket.
Task 4. Create a BigQuery dataset
Create a dataset in BigQuery dataset. This is where your tables are loaded in BigQuery.
In Cloud Shell, create the dataset named lake:
bq mk lake
Click Check my progress to verify your performed task.
Create the BigQuery Dataset named lake.
Task 5. Review and run the data ingestion pipeline
In this task, you review the pipeline code to see how it works. You then set up and run the pipeline.
The data ingestion pipeline ingests data from Cloud Storage into the BigQuery table using a TextIO source and a BigQueryIO destination. Specifically, the pipeline:
Ingests the files from Cloud Storage.
Filters out the header row in the files.
Converts the lines read to dictionary objects.
Outputs the rows to BigQuery.
Review the Python code for the data ingestion pipeline
Use the Cloud Shell Code Editor to review the pipeline code.
In the Cloud Shell menu bar, click Open Editor.
Navigate to dataflow_python_examples > dataflow_python_examples, and open the data_ingestion.py file.
Read the comments in the file, which explain what the code is doing.
This code populates a BigQuery table with the data files from Cloud Storage.
To return to Cloud Shell, click Open Terminal.
Set up the Docker container for the Dataflow jobs
Return to your Cloud Shell session to set up the required Python libraries.
The Dataflow jobs in this lab require Python3.8. To ensure you're on the proper version, run the Dataflow processes in a Python 3.8 Docker container.
Run the following in Cloud Shell to start up a Python container:
cd ~
docker run -it -e PROJECT=$PROJECT -v $(pwd)/dataflow-python-examples:/dataflow python:3.8 /bin/bash
This command pulls a Docker container with the latest stable version of Python 3.8 and executes a command shell to run the next commands within the container. The -v flag provides the source code as a volume for the container so that we can edit in Cloud Shell editor and still access it within the running container.
Once the container finishes pulling and starts executing in Cloud Shell, run the following to install apache-beam in that running container:
pip install apache-beam[gcp]==2.59.0
Next, in the running container in the Cloud Shell, change directories into where you linked the source code:
cd dataflow/
Set the project ID in the container:
export PROJECT={{{ project_0.project_id }}}
Run the data ingestion pipeline in the cloud
Run the following code to execute the data ingestion pipeline:
This code spins up the workers required and then shut them down when the pipeline is complete.
In the console title bar, type Dataflow in the Search field, and then click Dataflow in the search results.
When the Dataflow page opens, view the status of your job.
Click the job's name to watch its progress.
Once your Job Status is Succeeded, you can move to the next step. This ingestion pipeline takes approximately five minutes to start, complete the work, and then shutdown.
Navigate to BigQuery (Navigation menu > BigQuery) to see that your data has been populated.
Click your project name to see the usa_names table under the lake dataset.
Click the table then navigate to the Preview tab to see examples of the usa_names data.
Note: If you don't see the usa_names table, try refreshing the page or view the tables using the classic BigQuery UI.
Click Check my progress to verify your performed task.
Build a data ingestion pipeline.
Task 6. Review and run the data transformation pipeline
In this task, you review the data transformation pipeline to learn how it works. You then run the pipeline to process the Cloud Storage files and output the result to BigQuery.
The data transformation pipeline also ingests data from Cloud Storage into the BigQuery table using a TextIO source and a BigQueryIO destination, but with additional data transformations. Specifically, the pipeline:
Ingests the files from Cloud Storage.
Converts the lines read to dictionary objects.
Transforms the data which contains the year to a format BigQuery understands as a date.
Outputs the rows to BigQuery.
Review the Python code for the data transformation pipeline
In the Code Editor, open data_transformation.py.
Read the comments in the file, which explain what the code is doing.
Run the data transformation pipeline in the cloud
Run the following code to run the data transformation pipeline:
In the Dataflow page, click your job to view its Job status.
This Dataflow pipeline takes approximately five minutes to start, complete the work, and then shutdown.
Once your Job Status is Succeed in the Dataflow Job Status screen, in the console click Navigation menu > BigQuery to check to see that your data has been populated.
You should see the usa_names_enriched table under the lake dataset.
Click the table and navigate to the Preview tab to see examples of the usa_names_enriched data.
Note: If you don't see the usa_names_enriched table, try refreshing the page or view the tables using the classic BigQuery UI.
Click Check my progress to verify your performed task.
Build a data enrichment pipeline.
Task 8. Review and run the data lake to data mart pipeline
Now you build a Dataflow pipeline that reads data from two BigQuery data sources and then joins the data sources. Specifically, you:
Ingest files from two BigQuery sources.
Join the two data sources.
Filter out the header row in the files.
Convert the lines read to dictionary objects.
Output the rows to BigQuery.
Run the data ingestion pipeline to perform a data join and write the resulting table to BigQuery
You first review the data_lake_to_mart.py code to gain understanding of what it does. You then run the pipeline in the cloud.
In the Code Editor, open data_lake_to_mart.py file.
Read the comments in the file, which explain what the code is doing. This code joins two tables and write the results to new table in BigQuery.
Run the following code block to execute the pipeline:
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated April 1, 2025
Lab Last Tested April 1, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
I lab creano un progetto e risorse Google Cloud per un periodo di tempo prestabilito
I lab hanno un limite di tempo e non possono essere messi in pausa. Se termini il lab, dovrai ricominciare dall'inizio.
In alto a sinistra dello schermo, fai clic su Inizia il lab per iniziare
Utilizza la navigazione privata
Copia il nome utente e la password forniti per il lab
Fai clic su Apri console in modalità privata
Accedi alla console
Accedi utilizzando le tue credenziali del lab. L'utilizzo di altre credenziali potrebbe causare errori oppure l'addebito di costi.
Accetta i termini e salta la pagina di ripristino delle risorse
Non fare clic su Termina lab a meno che tu non abbia terminato il lab o non voglia riavviarlo, perché il tuo lavoro verrà eliminato e il progetto verrà rimosso
Questi contenuti non sono al momento disponibili
Ti invieremo una notifica via email quando sarà disponibile
Bene.
Ti contatteremo via email non appena sarà disponibile
Un lab alla volta
Conferma per terminare tutti i lab esistenti e iniziare questo
Utilizza la navigazione privata per eseguire il lab
Utilizza una finestra del browser in incognito o privata per eseguire questo lab. In questo modo eviterai eventuali conflitti tra il tuo account personale e l'account Studente, che potrebbero causare addebiti aggiuntivi sul tuo account personale.
In this lab, you build several data pipelines that ingest and transform data from a publicly available dataset into BigQuery.
Durata:
Configurazione in 0 m
·
Accesso da 90 m
·
Completamento in 90 m