Airflow ऑपरेटर

Python में Apache Airflow परिचय

Mike Metzger

Data Engineer

Operators

  • वर्कफ़्लो में एक सिंगल टास्क को दर्शाते हैं
  • आम तौर पर स्वतंत्र रूप से चलते हैं
  • सामान्यतः जानकारी साझा नहीं करते
  • अलग-अलग टास्क के लिए विभिन्न ऑपरेटर
@dag(
  dag_id="Example_Dag"
)
def example_dag():
  @task
  def task1():
    return "The result from task1"

  task1()

example_dag()
Python में Apache Airflow परिचय

@task (PythonOperator)

  • एक Python फंक्शन को निष्पादित करता है
  • किसी भी Python फंक्शन को @task से डेकोरेट कर सकते हैं
  • अन्य फंक्शन/टास्क के साथ डेटा पास कर सकते हैं
from airflow.sdk import task

@task def printme(): print("This goes in the logs!")
printme()
Python में Apache Airflow परिचय

@task आर्ग्युमेंट्स

  • एक साधारण Python फंक्शन की तरह टास्क/फंक्शन को आर्ग्युमेंट पास कर सकते हैं
@task
def printme(name: str):
    print(f"Hi {name} - This goes in the logs!")

printme(name='DataCamp')
# Adds: # Hi DataCamp - This goes in the logs! # to the Airflow logs
Python में Apache Airflow परिचय

@task.bash (BashOperator)

@task.bash
def bash_example():
  return "echo 'Example!'"

bash_example()
@task.bash
def run_cleanup():
  return "runcleanup.sh"

run_cleanup()
  • दी गई Bash कमांड या स्क्रिप्ट चलाता है
  • कमांड को एक टेम्पररी डायरेक्टरी में रन करता है
  • कमांड के लिए environment variables सेट कर सकते हैं
Python में Apache Airflow परिचय

टास्क dependencies

  • हर Dag में पूरे करने के लिए टास्क का सेट होता है
  • टास्क dependencies रनिंग ऑर्डर बताती हैं
  • dependencies बताने के कई तरीके हैं

 

कनेक्टेड टास्क वाला Airflow Dag जो उनके बीच dependency ऑर्डर दिखाता है

Python में Apache Airflow परिचय

Bitshift सिंटैक्स

>> और <<

task1() >> task2()

# task2 शुरू होने से पहले task1 पूरा होता है
task1() >> task2() >> task3()
# task2 से पहले task1 और task3 से पहले task2 पूरा होता है
task1() >> task3() task2() >> task3()
# task1 और task2 साथ चल सकते हैं पर दोनों के पूरा होने के बाद ही task3 चलेगा
Python में Apache Airflow परिचय

Bitshift सिंटैक्स उदाहरण

# मिलान करने से पहले सेल्स डेटा डाउनलोड करें
download_sales_data() >> reconcile()

# मिलान करने से पहले इन्वेंटरी डेटा डाउनलोड करें
download_inventory_data() >> reconcile()

 

  • दोनों के पूरा होने के बाद ही reconciling होगा, पर क्रम निर्दिष्ट नहीं है
Python में Apache Airflow परिचय

अभ्यास करते हैं!

Python में Apache Airflow परिचय

Preparing Video For Download...