使用 URI 從 SQLite 讀取資料
已經準備好一個本機的 SQLite 資料庫,裡面包含團隊每週使用的數位格式摘要。請使用 Polars 的以 URI 為基礎的讀取器,並搭配 ADBC 引擎。它會以 Arrow 的欄式格式傳輸資料,讓 Polars 可直接使用,而不需要逐列的 Python 轉換。
連線 URI 在 uri,SQL 查詢在 query。
本練習屬於課程
使用 Polars 擴充與最佳化資料管線
練習說明
- 使用 Polars 的 URI 型讀取函式來執行查詢。
- 將資料庫引擎設為
"adbc"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Read the SQL query result into a Polars DataFrame
result = pl.____(
query=query,
uri=uri,
# Use the ADBC engine
engine="____",
)
print(result)