ELT 裡的「T」
別忘了 ELT!這裡已經幫你定義好 extract() 和 load() 函式。現在只差完成 transform() 函式,然後執行整條 pipeline。加油!
本練習屬於課程
使用 Python 的 ETL 與 ELT
練習說明
- 更新
transform()函式,對data_warehouse物件呼叫.execute()方法。 - 使用剛更新的
transform()函式,將raw_sales_data來源資料表轉換後,寫入total_sales目標資料表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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="____")