> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nx1cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trino in NexusOne

> Overview of Trino, a distributed SQL engine used for querying data across sources in NexusOne.

Trino is a fast, distributed SQL engine built for interactive analytics across large and
diverse datasets.

Trino enables several key capabilities in NexusOne:

* Self-service analytics across curated and raw datasets
* OpenID Connect (OIDC) for unified authentication and authorization
* Federated SQL queries across Iceberg, Hive, PostgreSQL, and more
* BI dashboards powered by Superset
* DataOps workflows for validating and inspecting catalog data
* AI-assisted SQL generation

By providing a single execution layer for all analytical workloads, Trino forms a core
part of NexusOne's data architecture.

## Environment configuration

This section describes how the NexusOne team configured Trino, and how
different client tools connect to the service.

### Accessing the Trino UI

Trino provides that displays the details about the cluster. You can access
the Trino UI on the NexusOne cluster using the following URL:

```bash theme={null}
https://trino-app.<client>.nx1cloud.com/ui/
```

<Note>
  When you purchase NexusOne, you receive a client name.
  Replace `client` with your assigned client name.
</Note>

After visiting the URL, enter your NexusOne credentials to log in.

### Trino client setup

Within NexusOne, Trino supports OAuth 2.0 authenticated connections for JDBC, Python,
and the command-line tool clients.

#### Python

Example of connecting to Trino using Python.

```python theme={null}
from trino.dbapi import connect
from trino.auth import OAuth2Authentication

conn = connect(
    host="trino-app.<client>.nx1cloud.com",
    port=443,
    http_scheme="https",
    user="your_username",
    password="your_password",
    verify=False, #OPTIONAL FOR SSL ERROR
    catalog="iceberg",
    schema="default"
)
```

Use your NexusOne credentials as the `user` and `password`.

#### JDBC

Example of connecting to Trino using JDBC.

```python theme={null}
jdbc:trino://trino-app.<client>.nx1cloud.com:443/iceberg/default?SSL=true
```

#### Command-line tool

Example of connecting to Trino using a command-line tool.

```bash theme={null}
java -jar trino.jar \
  --user <user_id> \
  --server https://trino-app.<client>.nx1cloud.com/ \
  --catalog iceberg \
  --schema default \
  --debug
```

Use your NexusOne credential as the `user`.

### Iceberg/Hive integration

Trino integrates directly with the NexusOne data platform through preconfigured Iceberg and
Hive catalogs. These catalogs use S3 as the underlying storage layer for all datasets and
a Hive Metastore for providing centralized table and schema metadata.

### Superset integration

Superset connects to Trino using OAuth 2.0. Each Trino catalog appears as a database, and
each schema inside a catalog is available for querying in SQL Lab, Superset's interactive
SQL editor.

Connection example:

```python theme={null}
trino://token@trino-app.<client>.nx1cloud.com/iceberg/default?auth=oauth
```

Once connected, Superset uses Trino to run queries, create charts, and build dashboards.

## Types of Trino queries

Trino supports different types of queries depending on the purpose and data sources.
Understanding these types helps you choose the right approach when analyzing data.

### Analytical queries

Analytical queries interact with data within a single catalog or schema.

One example is counting employees per job role in a single table, `employees1`,
and calculating their average salary.

```sql theme={null}
SELECT job_id, COUNT(*) AS employee_count, AVG(salary) AS avg_salary
FROM employees1
GROUP BY job_id
ORDER BY employee_count DESC;
```

### Federated queries

Federated queries combine data across multiple catalogs or schemas.

One example is aggregating employee data by department, combining information from an
Iceberg table, `employees1`, and a Hive table, `departments`, in a single query.

```sql theme={null}
SELECT d.department_name,
       COUNT(e.employee_id) AS total_employees,
       AVG(e.salary) AS avg_salary,
       MAX(e.salary) AS max_salary
FROM iceberg.demo.employees1 e
JOIN hive.default.departments d
ON e.department_id = d.department_id
GROUP BY d.department_name
ORDER BY avg_salary DESC;
```

Understanding these types helps you decide which queries to use.

## Query execution management

Trino provides system-level mechanisms to keep query execution efficient in a multi-tenant
environment such as NexusOne. This includes the following:

* Parallel query execution across Kubernetes nodes
* Configurable query management properties that control query behavior and resource
  usage, such as:
  * `retry-policy`: Defines how many times and how often to retry a failed query
  * `query_max_run_time`: Maximum time a query can run before Trino stops it
  * `query_max_memory`: Maximum memory a query can use during execution
  * `query_max_execution_time`: Maximum CPU execution time a query can consume

## Additional resources

* To learn about best practices when using Trino, refer to the
  [Trino best practices](./trino-best-practices) page.
* To learn practical ways to use Trino in the NexusOne environment, refer to the
  [Trino hands-on examples](./trino-hands-on-examples) page.
* For more details about Trino, refer to the [Trino](https://trino.io/docs/current/) official documentation.
* If you are using the NexusOne portal and want to learn how to launch Trino, refer to the
  [Launch a hosted app](/documentation/platform/tasks/launch-a-hosted-app) page.
