Note
这些文件系统并未在C++中实现,因此它们的性能可能无法与httpfs
扩展提供的相媲美。
还值得注意的是,由于它们是第三方库,可能包含我们无法控制的错误。
DuckDB 对 fsspec
文件系统的支持允许查询 DuckDB 的 httpfs
扩展 不支持的文件系统中的数据。fsspec
有大量的 内置文件系统,还有许多 外部实现。此功能仅在 DuckDB 的 Python 客户端中可用,因为 fsspec
是一个 Python 库,而 httpfs
扩展在许多 DuckDB 客户端中都可用。
以下是使用fsspec
查询Google Cloud Storage中的文件的示例(而不是使用他们的S3兼容API)。
首先,您必须安装 duckdb
和 fsspec
,以及您选择的文件系统接口。
pip install duckdb fsspec gcsfs
然后,您可以注册您想要查询的任何文件系统:
import duckdb
from fsspec import filesystem
# this line will throw an exception if the appropriate filesystem interface is not installed
duckdb.register_filesystem(filesystem('gcs'))
duckdb.sql("SELECT * FROM read_csv('gcs:///bucket/file.csv')")
Note
这些文件系统并未在C++中实现,因此它们的性能可能无法与
httpfs
扩展提供的相媲美。 还值得注意的是,由于它们是第三方库,可能包含我们无法控制的错误。