# Trino Reverse ETL Source


[Trino](https://trino.io/) is a distributed SQL query engine for efficient, low-latency big data analytics.

RudderStack supports Trino as a data source from which you can ingest data and route it to your desired downstream destinations.

## Prerequisites: Trino server setup

Before you set up Trino as a source in RudderStack, make sure your Trino server is configured correctly by following these sections:

- RudderStack supports only [password file authentication](https://trino.io/docs/current/security/password-file.html) mechanism for this source. Make sure to enable [password file authentication](https://trino.io/docs/current/security/password-file.html#password-authenticator-configuration) for your Trino instance and [create a password file](https://trino.io/docs/current/security/password-file.html#creating-a-password-file).
- RudderStack uses the [file-based access control](https://trino.io/docs/current/security/file-system-access-control.html) mechanism for Trino. To use the access control plugin, see [Configuration](https://trino.io/docs/current/security/file-system-access-control.html#configuration) section.
- This integration supports only the [Apache Hive connector](https://trino.io/docs/current/connector/hive.html) currently. To use this connector, make sure to add the following [configuration](https://trino.io/docs/current/connector/hive.html#general-configuration) in the catalog properties file using the Hive connector:

```
hive.allow-drop-table=true
hive.metastore.thrift.delete-files-on-drop=true
```

## Grant permissions {#granting-permissions}

Before you set up Trino as a source, you must grant certain permissions on your Trino instance for RudderStack to access data from it.

Run the SQL queries listed in the following sections in the  **exact order** to grant these permissions:
 
### Step 1: Assign read access to tables {#step-1-assigning-read-access-to-tables}

This step gives RudderStack the necessary permissions to read the relevant table records in Trino.

{{< info >}}
RudderStack uses the [file-based access control](https://trino.io/docs/current/security/file-system-access-control.html) mechanism for this integration.
{{< /info >}}

To sync a table `sample_table` in `user_schema` for a user `test`, copy the below JSON in to your [access control config](https://trino.io/docs/current/security/file-system-access-control.html#configuration) JSON file:

```json
{
  "tables": [{
    "user": "test",  // Replace with your RudderStack user name
    "catalog": "catalog_name ", // Replace with the catalog you wish to sync
    "schema": "user_schema ", 
    "table": "sample_table ",
    "privileges": ["SELECT"]
  }]
}
```

### Step 2: Create RudderStack schema and grant permissions {#creating-the-rudderstack-schema-and-granting-permissions}

```sql
CREATE SCHEMA "_rudderstack"
```

To add this schema to a particular location, run the following query:

```sql
CREATE SCHEMA "_rudderstack" WITH (location = "s3://<your_location>/")
```

{{< warning >}}
Create the `_rudderstack` schema before syncing your data. **Do not change this name**.

See [`_rudderstack` Schema Reference]({{< ref "data-pipelines/reverse-etl/developer-guides/rudderstack-schema.md" >}}) for more details.
{{< /warning >}}

### Step 3: Grant ownership to `_rudderstack` schema {#step-3-granting-ownership-to-_rudderstack-schema}

The following grants RudderStack the necessary permissions to perform relevant actions on the tables in the `_rudderstack` schema:

```json
{
  "catalogs": [{
    "user": "test",
    "catalog": "catalog_name ",
    "allow": "all"
  }],
  "schemas": [{
    "user": "test",
    "catalog": "catalog_name ",
    "schema": "_rudderstack ",
    "owner": true
  }],
  "tables": [{
    "user": "test",
    "catalog": "catalog_name ",
    "schema": "_rudderstack ",
    "privileges": ["SELECT",
      "INSERT",
      "DELETE",
      "UPDATE",
      "OWNERSHIP"
    ]
  }]
}
```

## Set up Trino source in RudderStack {#setting-up-the-trino-source-in-rudderstack}

1. Log in to your [RudderStack dashboard](https://app.rudderstack.com/).
2. On the **Connections** page, click **Add source**.
3. Under **Sources**, click **Reverse ETL** and select **Trino**.

### Configure warehouse credentials {#configuring-connection-credentials}

You can choose to proceed with your existing warehouse credentials if you have configured them in the RudderStack dashboard previously. Otherwise, click **Add new credentials** to add new credentials for your warehouse.

- **Host**: Enter the host name or IP address of your Trino coordinator server.

{{< warning >}}
Make sure to enter only the host name and not the complete URL. Otherwise, you will encounter an error. 

For example, if the URL is `https://trino-server.example.com`, host name should be `trino-server.example.com`.
{{< /warning >}}

- **Catalog Name**: Specify the catalog to use when RudderStack executes queries in Trino.
- **User**: Enter the user with relevant access to the above settings.
- **Password**: Enter the password for the above user.
- **Port**: Enter the port number of your Trino coordinator server. This is an optional setting.

Click the **Verify** button on the top right. RudderStack will then [verify and validate your credentials](#faq). Once verified, click **Continue** to proceed.

### Specify name and source type

{{< customreadfile "/includes/retl/retl-name-sourcetype.md" >}}

#### **Use warehouse table as source**

{{< customreadfile "/includes/retl/table-as-source.md" >}}

#### **Use model as source**

{{< customreadfile "/includes/retl/model-as-source.md" >}}

#### **Use audience as source**

{{< customreadfile "/includes/retl/audience-as-source.md" >}}

### Review and complete setup

{{< customreadfile "/includes/retl/review-retl-setup.md" >}}

## Connect destination

{{< customreadfile "/includes/retl/connect-retl-destination.md" >}}

## Update source configuration and settings

{{< customreadfile "/includes/retl/update-retl-source-configuration.md" >}}

## FAQ 

#### **Which Trino connectors are supported for the Trino source integration?**

The Trino source supports only the [Apache Hive connector](https://trino.io/docs/current/connector/hive.html) currently. 

To use this connector, make sure to add the following [configuration](https://trino.io/docs/current/connector/hive.html#general-configuration) in your object store:

```
hive.allow-drop-table=true
hive.metastore.thrift.delete-files-on-drop=true
```

#### **Which data types are supported for this integration?**

The Trino source supports all data types listed in the [Trino documentation](https://trino.io/docs/current/language/types.html) except the [Row data type](https://trino.io/docs/current/language/types.html#row).

{{< customreadfile "/includes/retl/retl-faq.md" >}}

<br />
