TECHNOLOGIESTieInn Technologies

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 poke mode hold a worker slot the whole time; use mode="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_APPEND duplicate 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
5 questions

    Sensors and Google Cloud operators

  1. Question 1easy

    What does a sensor task do?

  2. Sensors and Google Cloud operators

  3. Question 2medium

    A sensor may wait up to 5 hours for a partner file. Which mode is better, and why?

  4. Sensors and Google Cloud operators

  5. Question 3medium

    What happens if a sensor has no sensible timeout and the file never arrives?

  6. Sensors and Google Cloud operators

  7. Question 4medium

    A daily task loads one day's file into raw.orders${{ ds_nodash }}. Which write disposition makes reruns safe?

  8. Sensors and Google Cloud operators

  9. Question 5hard

    Write tasks that wait for gs://shop-landing/sales/dt={{ ds }}/sales.parquet (reschedule mode, 4-hour timeout), load it into shop-data-prod.raw.sales replacing the day's partition, then run CALL sales.build_daily('{{ ds }}') in BigQuery.

    Write your answer on your own machine, then compare with the solution.

7 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.