跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

Trino

最后更新 查看 MarkdownAgent 设置

以下是使用 Trino ↗ 连接 Basin Catalog 的示例。有关使用 Trino 连接 Basin Catalog 的更多信息,请参阅 Trino 文档 ↗。

前提条件

设置

创建用于 catalog 配置的本地目录并切换到该目录

mkdir -p trino-catalog && cd trino-catalog/

创建名为 r2.properties 的配置文件,用于连接 Basin Catalog:

# r2.properties
connector.name=iceberg

# R2 Configuration
fs.native-s3.enabled=true
s3.region=auto
s3.aws-access-key=<Your R2 access key>
s3.aws-secret-key=<Your R2 secret>
s3.endpoint=<Your R2 endpoint>
s3.path-style-access=true

# Basin Catalog Configuration
iceberg.catalog.type=rest
iceberg.rest-catalog.uri=<Your Basin Catalog URI>
iceberg.rest-catalog.warehouse=<Your Basin Catalog warehouse>
iceberg.rest-catalog.security=OAUTH2
iceberg.rest-catalog.oauth2.token=<Your R2 authentication token>

示例用法

  1. 使用 R2 catalog 配置启动 Trino:

    # Create a local directory for the catalog configuration
    mkdir -p trino-catalog
    
    # Place your r2.properties file in the catalog directory
    cp r2.properties trino-catalog/
    
    # Run Trino with the catalog configuration
    docker run -d \
      --name trino-r2 \
      -p 8080:8080 \
      -v $(pwd)/trino-catalog:/etc/trino/catalog \
      trinodb/trino:latest
  2. 连接到 Trino 并查询你的 Basin Catalog:

    # Connect to the Trino CLI
    docker exec -it trino-r2 trino
  3. 在 Trino CLI 中运行以下命令:

    -- Show all schemas in the R2 catalog
    SHOW SCHEMAS IN r2;
    
    -- Create a schema in the R2 catalog
    CREATE SCHEMA r2.example_schema;
    
    -- Create a table with some values in it
    CREATE TABLE r2.example_schema.yearly_clicks (
        year,
        clicks
    )
    WITH (
       partitioning = ARRAY['year']
    )
    AS VALUES
        (2021, 10000),
        (2022, 20000);
    
    -- Show tables in a specific schema
    SHOW TABLES IN r2.example_schema;
    
    -- Query your Iceberg table
    SELECT * FROM r2.example_schema.yearly_clicks;

这篇文档对您有帮助吗?