feat(data): 添加 DuckDB 只读模式支持

- Storage 类默认使用 read_only=True 模式,允许多进程并发读取
- ThreadSafeStorage 自动使用 read_only=False 模式,用于数据同步写入
- catalog.query_duckdb_to_polars 函数使用只读连接
This commit is contained in:
2026-03-11 21:33:08 +08:00
parent f3b3560d26
commit e8ac9d8662
4 changed files with 204 additions and 189 deletions

View File

@@ -439,6 +439,7 @@ def query_duckdb_to_polars(query: str, db_path: str) -> pl.LazyFrame:
"""执行 DuckDB 查询并返回 Polars LazyFrame。
使用 duckdb.connect().sql(query).pl() 实现高速数据流转。
默认使用 read_only=True 模式,允许多进程并发读取。
Args:
query: SQL 查询语句
@@ -447,7 +448,7 @@ def query_duckdb_to_polars(query: str, db_path: str) -> pl.LazyFrame:
Returns:
Polars LazyFrame
"""
conn = duckdb.connect(db_path)
conn = duckdb.connect(db_path, read_only=True)
try:
# DuckDB -> Polars 高速转换
df = conn.sql(query).pl()