使用自訂的批次 sink
當需要 Polars 原生不支援的客製處理時,你可以傳入自己的函式。團隊想示範這個模式,雖然他們平常會用內建的 sink。請將 digital_rows 串流傳入預先定義好的 record_batch 函式。
digital_rows 已經預先載入。也已為你定義了 record_batch(batch) 函式,會把每個批次的列數與結帳金額總和記錄到 batch_summaries。
本練習屬於課程
使用 Polars 擴充與最佳化資料管線
練習說明
- 在串流引擎上,以每 5,000 列為一個批次,將
digital_rows串流傳入該函式。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Stream batches through the record_batch function
digital_rows.____(
record_batch,
____=5_000,
____="streaming",
)
result = pl.DataFrame(batch_summaries)
print(result)