Posts

Showing posts with the label airflow tutorial

Manage flow of tasks - Airflow Tutorial Trigger Rules, Conditional Branching, Setup Teardown, Latest Only, Depends On Past

  Hello Data Pros, and welcome back to another exciting episode of our Apache Airflow series! ****  Code lines at the End  **** Today, we'll explore how to manage the flow of tasks in Airflow—a critical step in orchestrating efficient data pipelines !   With the default airflow settings, a task is executed only when all its dependencies complete successfully. However, in real-world projects, customizing this default behaviour becomes essential to address a vast number of use cases.   For example, you might need to dynamically pick and run a specific branch depending on the outcome of a preceding task, while skipping the remaining branches. The Branch Python Operator facilitates this feature, by allowing you to select a branch through a user-defined Python function. Within this function, you can implement the logic to determine the appropriate branch, and should ensure that it returns the task ID of the downstream task to be executed next.   All the code lin...

Airflow Tutorial - Xcom | How to Pass data between tasks

  Hello Data Pros,  In our last blog, we covered deferrable operators and triggers! Now, it’s time to explore Airflow's X-com feature! Let's dive right in! By design, Airflow tasks are isolated! which means they cannot exchange data with each other at run time! However, we frequently come across situations that require sharing data between tasks.   For instance, you might need to extract a value from a table, and based on that value, perform something in the next task! or you may need to create a file with a dynamic name, such as one with a timestamp, and process the same file in the next task.   This is where X-com comes into play. X-com, abbreviated as 'cross-communication,' provides a mechanism that allows tasks to exchange data with each other.   Let’s consider this example Dag. In the first task, we create a file! And in the second task, we upload the same file to S3. With the current setup, this process works well! because we have the 'replace' parameter s...

Airflow Tutorial - Sensors | What are Airflow sensors | How sensors Work | Examples | s3keysensor

  Hello Data Pros,  In our previous blog, we explored the power of Airflow Variables and Connections and how to use them effectively in your Dags. Today, we're going to deep dive into the world of Airflow sensors!   As we mentioned already, Airflow sensors are a special type of operator that are designed to wait for a specific condition to be met! At regular intervals, they check to see if the condition is met. Once it’s met, the corresponding task is marked successful, allowing their downstream tasks to execute. Sensors make your Dags more event-driven, scattering use cases such as when a task needs to wait for a file to be created, Or a database table to be updated, or an external API to become available.   Here is a simple Dag consisting of two tasks. The first task uses S3KeySensor, which waits for a file to be available in the AWS S3 bucket. Once the file is ready, the next task loads the file into a Snowflake table.   Let's see how it works in the Airflow ...

Airflow Tutorial - Variables and Connections

Hello Data Pros,  In our last blog, we covered the fundamental concepts of Apache Airflow, including  dags , tasks and operators! In addition, we demonstrated the importance of the airflow configuration file, and the provider packages!   Today, we’ll learn about the power of Airflow Variables and Connections and how to use them effectively within your  Dags .   Let's start with Apache Airflow Variables! Variables are like little storage containers for values, that you can reuse across your  dags . Instead of hardcoding values, you can store them as variables, and reference them with its name whenever needed.   Technically each variable is a key and a value pair. You can think of the key as the variable name and the value as the data it holds.   There are two types of Airflow variables! One, Regular variables, Where the value can be any string. Two, JSON variables, where the value is a JSON string.   Let’s consider I have a  dag , that in...