diff --git a/getting-started/trino/README.md b/getting-started/trino/README.md new file mode 100644 index 0000000000..91031340f9 --- /dev/null +++ b/getting-started/trino/README.md @@ -0,0 +1,52 @@ + + +# Getting Started with Trino and Apache Polaris + +This getting started guide provides a docker-compose file to set up [Trino](https://trino.io/) with Apache Polaris. Apache Polaris is configured as an Iceberg REST Catalog in Trino. + +## Run the docker-compose file +To start the docker-compose file, run this command from the repo's root directory: +``` +docker-compose -f getting-started/trino/docker-compose-trino.yml up +``` + +## Run Trino queries via Trino ClI +To access the Trino CLI, run this command +``` +docker exec -it trino-trino-1 trino +``` +Note, `trino-trino-1` is the name docker container. + +Example Trino queries: +``` +SHOW CATALOGS; +SHOW SCHEMAS FROM iceberg; +SHOW TABLES FROM iceberg.information_schema; +DESCRIBE iceberg.information_schema.tables; + +CREATE SCHEMA iceberg.tpch; +CREATE TABLE iceberg.tpch.test_polaris AS SELECT 1 x; +SELECT * FROM iceberg.tpch.test_polaris; +``` + +## Note +The polaris catalog setup script use the credential `principal:root;realm:default-realm`. This credential is used so users do not need to fetch credentials from Apache Polaris' console output. + +An example catalog is created in Apache Polaris using the `curl` command. See `create-polaris-catalog.sh` for details. diff --git a/getting-started/trino/create-polaris-catalog.sh b/getting-started/trino/create-polaris-catalog.sh new file mode 100644 index 0000000000..e5eb963319 --- /dev/null +++ b/getting-started/trino/create-polaris-catalog.sh @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +PRINCIPAL_TOKEN="principal:root;realm:default-realm" + +# Use local filesystem by default +curl -i -X POST -H "Authorization: Bearer $PRINCIPAL_TOKEN" -H 'Accept: application/json' -H 'Content-Type: application/json' \ + http://polaris:8181/api/management/v1/catalogs \ + -d '{ + "catalog": { + "name": "polaris", + "type": "INTERNAL", + "readOnly": false, + "properties": { + "default-base-location": "file:///tmp/polaris/" + }, + "storageConfigInfo": { + "storageType": "FILE", + "allowedLocations": [ + "file:///tmp" + ] + } + } + }' diff --git a/getting-started/trino/docker-compose-trino.yml b/getting-started/trino/docker-compose-trino.yml new file mode 100644 index 0000000000..3c9ab36f5d --- /dev/null +++ b/getting-started/trino/docker-compose-trino.yml @@ -0,0 +1,56 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +services: + polaris: + build: + context: ../../ + ports: + - "8181:8181" + - "8182" + environment: + AWS_REGION: us-west-2 + GOOGLE_APPLICATION_CREDENTIALS: $GOOGLE_APPLICATION_CREDENTIALS + AZURE_TENANT_ID: $AZURE_TENANT_ID + AZURE_CLIENT_ID: $AZURE_CLIENT_ID + AZURE_CLIENT_SECRET: $AZURE_CLIENT_SECRET + # add aws keys as dropwizard config + JAVA_OPTS: -Ddw.awsAccessKey=$AWS_ACCESS_KEY_ID -Ddw.awsSecretKey=$AWS_SECRET_ACCESS_KEY + + healthcheck: + test: ["CMD", "curl", "http://localhost:8182/healthcheck"] + interval: 10s + timeout: 10s + retries: 5 + + create-polaris-catalog: + image: curlimages/curl + depends_on: + polaris: + condition: service_healthy + volumes: + - ./create-polaris-catalog.sh:/create-polaris-catalog.sh + command: ["/bin/sh", "/create-polaris-catalog.sh"] + + trino: + image: trinodb/trino:latest + ports: + - "8080:8080" + volumes: + - ./trino-config/catalog:/etc/trino/catalog diff --git a/getting-started/trino/trino-config/catalog/iceberg.properties b/getting-started/trino/trino-config/catalog/iceberg.properties new file mode 100644 index 0000000000..a5075530f7 --- /dev/null +++ b/getting-started/trino/trino-config/catalog/iceberg.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +connector.name=iceberg +iceberg.catalog.type=rest +iceberg.rest-catalog.uri=http://polaris:8181/api/catalog +iceberg.rest-catalog.security=OAUTH2 +iceberg.rest-catalog.oauth2.token=principal:root;realm:default-realm +iceberg.rest-catalog.warehouse=polaris