การติดตาม data pipeline

ETL และ ELT ด้วย Python

Jake Roach

Data Engineer

การติดตาม data pipeline

ควรติดตาม data pipeline เพื่อตรวจจับการเปลี่ยนแปลงของข้อมูลและความล้มเหลวในการทำงาน

  • ข้อมูลที่หายไป
  • ชนิดข้อมูลที่เปลี่ยนแปลง
  • แพ็กเกจที่ถูกยกเลิกหรือเปลี่ยนแปลงฟังก์ชันการทำงาน

$$

ขั้นตอนการ logging สำหรับ data pipeline

ETL และ ELT ด้วย Python

การ logging ประสิทธิภาพของ data pipeline

  • บันทึกประสิทธิภาพขณะทำงาน
  • เป็นจุดเริ่มต้นในการแก้ปัญหาเมื่อเกิดข้อผิดพลาด
import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

# Create different types of logs
logging.debug(f"Variable has value {path}")
logging.info("Data has been transformed and will now be loaded.")
DEBUG: Variable has value raw_file.csv
INFO: Data has been transformed and will now be loaded.
ETL และ ELT ด้วย Python

การ logging คำเตือนและข้อผิดพลาด

import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

# Create different types of logs
logging.warning("Unexpected number of rows detected.")
logging.error("{ke} arose in execution.")
WARNING: Unexpected number of rows detected.
ERROR: KeyError arose in execution.
ETL และ ELT ด้วย Python

การจัดการข้อยกเว้นด้วย try-except

try:
    # Execute some code here
    ...

except:
    # Logging about failures that occured
    # Logic to execute upon exception
    ...

  • ช่วยให้รันโค้ดเพิ่มเติมได้เมื่อเกิดข้อผิดพลาด
ETL และ ELT ด้วย Python

การจัดการข้อยกเว้นเฉพาะด้วย try-except

ระบุข้อยกเว้นที่ต้องการในส่วน except

try:
    # Try to filter by price_change
    clean_stock_data = transform(raw_stock_data)
    logging.info("Successfully filtered DataFrame by 'price_change'")

except KeyError as ke:
    # Handle the error, create new column, transform
    logging.warning(f"{ke}: Cannot filter DataFrame by 'price_change'")
    raw_stock_data["price_change"] = raw_stock_data["close"] - raw_stock_data["open"]
    clean_stock_data = transform(raw_stock_data)

ETL และ ELT ด้วย Python

มาฝึกกันเถอะ!

ETL และ ELT ด้วย Python

Preparing Video For Download...