以下示例展示如何使用 DuckDB ↗ 连接到 Basin Catalog。有关使用 DuckDB 连接 Basin Catalog 的更多信息,请参阅 DuckDB 文档 ↗。
- 注册 Cloudflare 账户 ↗。
- 创建 R2 存储桶,并启用数据目录。
- 创建 R2 API 令牌,并授予 R2 和数据目录权限。
- 安装 DuckDB ↗。
- 注意:需要 DuckDB 1.4.0 ↗ 或更高版本,才能附加并写入 Iceberg REST Catalogs ↗。
- 注意:DuckDB 目前不支持 ↗对分区表执行
DELETE。
在 DuckDB CLI ↗(命令行界面)中运行以下命令:
-- Install the Iceberg DuckDB extension if needed, then load the extension.
INSTALL iceberg;
LOAD iceberg;
-- Install and load httpfs extension for reading/writing files over HTTP(S).
INSTALL httpfs;
LOAD httpfs;
-- Create a DuckDB secret to store Basin Catalog credentials.
CREATE SECRET r2_secret (
TYPE ICEBERG,
TOKEN '<token>'
);
-- Attach Basin Catalog with the following ATTACH statement.
ATTACH '<warehouse_name>' AS my_r2_catalog (
TYPE ICEBERG,
ENDPOINT '<catalog_uri>'
);
-- Create the default schema in the catalog and set it as the active schema.
CREATE SCHEMA my_r2_catalog.default;
USE my_r2_catalog.default;
-- Create and populate a sample Iceberg table with data.
CREATE TABLE my_iceberg_table AS SELECT a FROM range(4) t(a);
-- Show all available tables.
SHOW ALL TABLES;
-- Query the Iceberg table you just created.
SELECT * FROM my_r2_catalog.default.my_iceberg_table;