Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

Trino

最終更新 Markdown で表示Agent セットアップ

Trino を R2 Data Catalog に接続する例です。Trino から R2 Data Catalog への接続の詳細は、Trino のドキュメント を参照してください。

前提条件

セットアップ

カタログ設定用のローカルディレクトリを作成し、そのディレクトリに移動します。

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

R2 Data Catalog 接続用の設定ファイル r2.properties を作成します。

# 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

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

使用例

  1. R2 カタログ設定で 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 に接続し、R2 Data 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;

役に立ちましたか?