<a id="cloud-tableflow-query-with-trino"></a>

# Query Iceberg Tables with Trino and Tableflow in Confluent Cloud

Trino is an open-source query engine that you can use to query your
Tableflow tables. Trino can query your Apache Iceberg™ tables by connecting
directly to the Tableflow Catalog via the Iceberg REST API.

In this example, you launch Trino in a Docker container on your local machine.
For instructions about running Trino in a Docker container, see
[Trino in a Docker container](https://trino.io/docs/current/installation/containers.html).

In production, you should host your Trino server instance in the cloud-region
where your Tableflow tables are stored, to decrease latency and reduce data
egress fees.

## Prerequisites

- A Kafka topic with Tableflow enabled. For more information, see the
  Tableflow Quick Start <cloud-tableflow-quick-start-managed-storage>
- A Confluent API Key with Tableflow permissions.
- Docker is installed and running in your development environment.

## Step 1: Create a catalog configuration file

1. Create a directory named *catalog*.
   ```bash
   mkdir catalog
   ```
2. In the *catalog* directory, create a file named *tableflow.properties*.
   ```bash
   touch catalog/tableflow.properties
   ```
3. Copy the following property settings into *tableflow.properties*.
   ```properties
   # tableflow.properties

   connector.name=iceberg
   iceberg.catalog.type=rest
   iceberg.rest-catalog.oauth2.credential=<api-key>:<api-secret>
   iceberg.rest-catalog.security=OAUTH2
   iceberg.rest-catalog.uri=<Tableflow REST Catalog URI>
   # REST Catalog URI Example: https://tableflow.{CLOUD_REGION}.aws.confluent.cloud/iceberg/catalog/organizations/{ORG_ID}/environments/{ENV_ID}
   iceberg.rest-catalog.vended-credentials-enabled=true

   fs.native-s3.enabled=true
   s3.region=<Confluent Cluster Region>
   # S3 Region Example: us-west-2

   iceberg.security=read_only
   ```

## Step 2: Start a Trino container

1. In your terminal, change into the catalog directory.
   ```bash
   cd catalog
   ```
2. Run the following command to start the Trino container with these
   options.
   - `--name`: Assign a name to the container.
   - `-d`: Run the container in the background.
   - `-p`: Publish the container’s port to the host.
   - `--volume`: Bind mount a volume.

   If you’re using custom storage with AWS, include your AWS credentials
   and environment variables. If you’re using Confluent Managed Storage (CMS), this
   isn’t necessary.
   - `-e AWS_PROFILE=default`: Use the default AWS profile from the
     `~/.aws/credentials` directory, if available.
   - `-e AWS_REGION=<region>`: Set the AWS region. Use your AWS region
     for `<region>`.
   - `-e AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)`: Injects
     your AWS Access Key ID from your AWS CLI configuration.
   - `-e AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)`:
     Injects your AWS Secret Access Key from your AWS CLI configuration.

   ```bash
   docker run -d \
     --name trino \
     -p 8080:8080 \
     -v $PWD:/etc/trino/catalog \
     -e AWS_PROFILE=default \
     -e AWS_REGION=us-east-1 \
     -e AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id) \
     -e AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key) \
     trinodb/trino
   ```
3. Run the following command to check that your Trino container is running.
   ```bash
   docker ps
   ```

## Step 3: Query your Tableflow table data

1. In your terminal, run the following command to start the Trino CLI client.
   ```bash
   docker exec -it trino trino
   ```

   Your terminal prompt should now appear as **trino>**.
2. Run the following Trino SQL query to query your Tableflow table data. Use
   your values for these options.
   - **tableflow.**: The name of your catalog properties file
   - **kafka-cluster-id**: Your Kafka cluster ID, which resembles *lck-xxxxxx*. Also, you
     can use your Kafka cluster name.
   - **<table-name>**: Your Kafka topic name

   ```sql
   SELECT * FROM tableflow."<kafka-cluster-id>".<table-name>
   ```

## Related content

- [Query with AWS](query-with-aws.md#cloud-tableflow-query-with-aws)
- [Query with DuckDB](query-with-duckdb.md#cloud-tableflow-query-with-duckdb)
- [Query with Flink](query-with-flink.md#cloud-tableflow-query-with-flink)
- [Query with Snowflake](query-with-snowflake.md#cloud-tableflow-query-with-snowflake)
- [Stream Processing with Confluent Cloud for Apache Flink](../../../../flink/overview.md#ccloud-flink)

#### NOTE
This website includes content developed at the [Apache Software Foundation](https://www.apache.org/)
under the terms of the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0.html).
