Sensors and Google Cloud operators
Airflow (Cloud Composer) · 12 questions
Short notes
Key idea
Sensors wait for something to happen (a file lands, another DAG finishes). Provider operators run work in cloud services, such as BigQuery jobs or copying files from Cloud Storage, without custom code.
Syntax
from airflow.providers.google.cloud.sensors.gcs import GCSObjectExistenceSensor
from airflow.providers.google.cloud.transfers.gcs_to_bigquery import GCSToBigQueryOperator
from airflow.providers.google.cloud.operators.bigquery import BigQueryInsertJobOperator
wait = GCSObjectExistenceSensor(task_id="wait", bucket="raw", object="orders/{{ ds }}.csv",
mode="reschedule", timeout=3*3600)
Example
wait for orders/{{ ds }}.csv → GCSToBigQueryOperator loads it into raw.orders → BigQueryInsertJobOperator runs the SQL that builds the mart. No custom Python is needed for any step.
Traps
- Sensors in
pokemode hold a worker slot the whole time; usemode="reschedule"or deferrable operators. - Always set a timeout, or a missing file blocks the run forever.
- The operator's service account needs IAM permissions on the bucket and dataset.
- Load jobs with
WRITE_APPENDduplicate data on retries; prefer partition overwrite.
Want the full lesson with step-by-step examples, a project and a certificate? Airflow (Cloud Composer) course, ₹120 →
Questions
5 free questions- Question 1easy
What does a sensor task do?
- Question 2medium
A sensor may wait up to 5 hours for a partner file. Which mode is better, and why?
- Question 3medium
What happens if a sensor has no sensible timeout and the file never arrives?
- Question 4medium
A daily task loads one day's file into
raw.orders${{ ds_nodash }}. Which write disposition makes reruns safe? - Question 5hard
Write tasks that wait for
gs://shop-landing/sales/dt={{ ds }}/sales.parquet(reschedule mode, 4-hour timeout), load it intoshop-data-prod.raw.salesreplacing the day's partition, then runCALL sales.build_daily('{{ ds }}')in BigQuery.Write your answer on your own machine, then compare with the solution.
Sensors and Google Cloud operators
Sensors and Google Cloud operators
Sensors and Google Cloud operators
Sensors and Google Cloud operators
Sensors and Google Cloud operators
7 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.