Bir veri hattını izleme

Python ile ETL ve ELT

Jake Roach

Data Engineer

Bir veri hattını izleme

Veri hatları, veri değişimleri ve çalıştırma hataları için izlenmelidir

  • Eksik veri
  • Kayan veri türleri
  • Paket kullanımdan kalkması veya işlev değişikliği

$$

Bir veri hattı için günlükleme iş akışı.

Python ile ETL ve ELT

Veri hattı performansını günlükleme

  • Çalıştırma sırasında performansı belgele
  • Çözüm başarısız olduğunda başlangıç noktası sağlar
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.
Python ile ETL ve ELT

Uyarı ve hataları günlükleme

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.
Python ile ETL ve ELT

try-except ile istisnaları ele alma

try:
    # Execute some code here
    ...

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

  • Hata olursa kod çalıştırmanın bir yolunu sağlar
Python ile ETL ve ELT

try-except ile belirli istisnaları ele alma

except bloğunda belirli istisnayı belirt

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)

Python ile ETL ve ELT

Hadi pratik yapalım!

Python ile ETL ve ELT

Preparing Video For Download...