From 5daa0a5d3bcef44817208d211c2be8cb1fb050fc Mon Sep 17 00:00:00 2001 From: Marc Selwan Date: Thu, 4 Sep 2025 12:02:20 -0700 Subject: [PATCH 1/6] Adding trino.mdx to the R2 Data Catalog examples Adding an example of connecting Trino to the R2 Data Catalog --- .../r2/data-catalog/config-examples/trino.mdx | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/content/docs/r2/data-catalog/config-examples/trino.mdx diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx new file mode 100644 index 000000000000000..c679d8e004e37b7 --- /dev/null +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -0,0 +1,91 @@ +--- +title: Apache Trino +pcx_content_type: example +--- + +Below is an example of using [Apache Trino](https://trino.io/) to connect to R2 Data Catalog. For more information on connecting to R2 Data Catalog with Trino, refer to [Trino documentation](https://trino.io/docs/current/connector/iceberg.html). + +## Prerequisites + +- Sign up for a [Cloudflare account](https://dash.cloudflare.com/sign-up/workers-and-pages). +- [Create an R2 bucket](/r2/buckets/create-buckets/) and [enable the data catalog](/r2/data-catalog/manage-catalogs/#enable-r2-data-catalog-on-a-bucket). +- [Create an R2 API token, key, and secret](/r2/api/tokens/) with both [R2 and data catalog permissions](/r2/api/tokens/#permissions). +- Install [Docker](https://docs.docker.com/get-docker/) to run the Trino container. + +## Setup + +Create a configuration file for your R2 Data Catalog connection: + +```properties +# r2.properties +connector.name=iceberg + +# R2 Configuration +fs.native-s3.enabled=true +s3.region=auto +s3.aws-access-key= +s3.aws-secret-key= +s3.endpoint= +s3.path-style-access=true + +# R2 Data Catalog Configuration +iceberg.catalog.type=rest +iceberg.rest-catalog.uri= +iceberg.rest-catalog.warehouse= +iceberg.rest-catalog.security=OAUTH2 +iceberg.rest-catalog.oauth2.token= +``` + +## Example usage + +Start Trino with the R2 catalog configuration: + +```bash +# 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 +``` + +Connect to Trino and query your R2 Data Catalog: + +```bash +# Connect to the Trino CLI +docker exec -it trino-r2 trino +``` + +In the Trino CLI, run the following commands: + +```sql +-- Show all schemas in the R2 catalog +SHOW SCHEMAS IN r2; + +-- Show all schemas 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; +``` \ No newline at end of file From 2d66b29d4349377e7ebed0eb376ae555f5441c77 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Fri, 5 Sep 2025 10:58:31 +0100 Subject: [PATCH 2/6] Apply suggestions from code review --- .../r2/data-catalog/config-examples/trino.mdx | 96 ++++++++++--------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx index c679d8e004e37b7..d5b251ec1085e31 100644 --- a/src/content/docs/r2/data-catalog/config-examples/trino.mdx +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -3,6 +3,8 @@ title: Apache Trino pcx_content_type: example --- +import { Steps } from "~/components"; + Below is an example of using [Apache Trino](https://trino.io/) to connect to R2 Data Catalog. For more information on connecting to R2 Data Catalog with Trino, refer to [Trino documentation](https://trino.io/docs/current/connector/iceberg.html). ## Prerequisites @@ -38,54 +40,56 @@ iceberg.rest-catalog.oauth2.token= ## Example usage -Start Trino with the R2 catalog configuration: - -```bash -# Create a local directory for the catalog configuration -mkdir -p trino-catalog + +1. Start Trino with the R2 catalog configuration: -# 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 -``` + ```bash + # Create a local directory for the catalog configuration + mkdir -p trino-catalog -Connect to Trino and query your R2 Data Catalog: + # Place your r2.properties file in the catalog directory + cp r2.properties trino-catalog/ -```bash -# Connect to the Trino CLI -docker exec -it trino-r2 trino + # 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 ``` -In the Trino CLI, run the following commands: - -```sql --- Show all schemas in the R2 catalog -SHOW SCHEMAS IN r2; - --- Show all schemas 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; -``` \ No newline at end of file +2. Connect to Trino and query your R2 Data Catalog: + + ```bash + # Connect to the Trino CLI + docker exec -it trino-r2 trino + ``` + +3. In the Trino CLI, run the following commands: + + ```sql + -- Show all schemas in the R2 catalog + SHOW SCHEMAS IN r2; + + -- Show all schemas 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; + ``` + \ No newline at end of file From e3410da8c48954d76ff8ed41fa3476c0bb47cbdb Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Fri, 5 Sep 2025 11:00:09 +0100 Subject: [PATCH 3/6] Apply suggestions from code review --- src/content/docs/r2/data-catalog/config-examples/trino.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx index d5b251ec1085e31..29b5f74db251f8c 100644 --- a/src/content/docs/r2/data-catalog/config-examples/trino.mdx +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -56,7 +56,7 @@ iceberg.rest-catalog.oauth2.token= -p 8080:8080 \ -v $(pwd)/trino-catalog:/etc/trino/catalog \ trinodb/trino:latest -``` + ``` 2. Connect to Trino and query your R2 Data Catalog: From 52590891d204c24bde7842b8adb95c6cb84ea09c Mon Sep 17 00:00:00 2001 From: Marc Selwan Date: Fri, 5 Sep 2025 09:52:47 -0700 Subject: [PATCH 4/6] simplified trino.mdx based on feedback from @jonesphillip - changed order of creating directory and files to make the steps flow better. --- .../docs/r2/data-catalog/config-examples/trino.mdx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx index c679d8e004e37b7..1d29d32f0addcaf 100644 --- a/src/content/docs/r2/data-catalog/config-examples/trino.mdx +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -13,8 +13,12 @@ Below is an example of using [Apache Trino](https://trino.io/) to connect to R2 - Install [Docker](https://docs.docker.com/get-docker/) to run the Trino container. ## Setup +```bash +# Create a local directory for the catalog configuration and change directories to it +mkdir -p trino-catalog && cd trino-catalog/ +``` -Create a configuration file for your R2 Data Catalog connection: +Create a configuration file called `r2.properties` for your R2 Data Catalog connection: ```properties # r2.properties @@ -41,12 +45,6 @@ iceberg.rest-catalog.oauth2.token= Start Trino with the R2 catalog configuration: ```bash -# 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 \ From aa0b17aae14e702cad8e460112244d89e34bc668 Mon Sep 17 00:00:00 2001 From: Marc Selwan Date: Fri, 5 Sep 2025 11:02:32 -0700 Subject: [PATCH 5/6] moved text out of code block moved text out of code block --- src/content/docs/r2/data-catalog/config-examples/trino.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx index b110517343c42c0..38b09d41979902b 100644 --- a/src/content/docs/r2/data-catalog/config-examples/trino.mdx +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -15,8 +15,8 @@ Below is an example of using [Apache Trino](https://trino.io/) to connect to R2 - Install [Docker](https://docs.docker.com/get-docker/) to run the Trino container. ## Setup -```bash # Create a local directory for the catalog configuration and change directories to it +```bash mkdir -p trino-catalog && cd trino-catalog/ ``` From a4803293fd0b442187d82aebc724ebd2ac4c939f Mon Sep 17 00:00:00 2001 From: Marc Selwan Date: Fri, 5 Sep 2025 11:03:32 -0700 Subject: [PATCH 6/6] fixed markdown typo in trino.mdx --- src/content/docs/r2/data-catalog/config-examples/trino.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/r2/data-catalog/config-examples/trino.mdx b/src/content/docs/r2/data-catalog/config-examples/trino.mdx index 38b09d41979902b..6c8e317d81e2886 100644 --- a/src/content/docs/r2/data-catalog/config-examples/trino.mdx +++ b/src/content/docs/r2/data-catalog/config-examples/trino.mdx @@ -15,7 +15,7 @@ Below is an example of using [Apache Trino](https://trino.io/) to connect to R2 - Install [Docker](https://docs.docker.com/get-docker/) to run the Trino container. ## Setup -# Create a local directory for the catalog configuration and change directories to it +Create a local directory for the catalog configuration and change directories to it ```bash mkdir -p trino-catalog && cd trino-catalog/ ```