"T" ใน ELT
อย่าลืม ELT! ฟังก์ชัน extract() และ load() ได้ถูกกำหนดไว้ให้แล้ว สิ่งที่เหลืออยู่คือกำหนดฟังก์ชัน transform() ให้เสร็จสมบูรณ์ แล้วรัน pipeline มาลุยกันเลย!
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
ETL และ ELT ด้วย Python
คำแนะนำการฝึกหัด
- อัปเดตฟังก์ชัน
transform()ให้เรียกใช้เมธอด.execute()บนออบเจกต์data_warehouse - ใช้ฟังก์ชัน
transform()ที่อัปเดตแล้วเพื่อเติมข้อมูลลงใน target tabletotal_salesโดย transform ข้อมูลจาก source tableraw_sales_data
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Complete building the transform() function
def transform(source_table, target_table):
data_warehouse.____(f"""
CREATE TABLE {target_table} AS
SELECT
CONCAT("Product ID: ", product_id),
quantity * price
FROM {source_table};
""")
extracted_data = extract(file_name="raw_sales_data.csv")
load(data_frame=extracted_data, table_name="raw_sales_data")
# Populate total_sales by transforming raw_sales_data
____(source_table="____", target_table="____")