# Trino

Marple integrates seamlessly with [Trino](https://trino.io/), a fast distributed SQL query engine.

What makes this connection particularly powerful is that Trino itself supports a wide range of underlying data sources, making all of them accessible through Insight as well.

### Required credentials

To connect, the following credentials are needed:

* Host
* User
* Password
* Port

### Queries

Queries are executed using SQL. Marple offers predefined queries for fetching datasets, signals, and time-series data. Below are some example queries:

* To retrieve **datasets**:

```sql
select
    concat("carId", ' ', session) as display_name,
    "carId",
    event,
    session,
    min(time) as start,
    max(time) as stop,
    realtime
  from {{TABLE}}
  group by "carId", event, session, realtime
```

* To retrieve a **signal list:**

```sql
select 
  name,
  sum(count) as count,
  CAST(max(count) AS double) * 1e9 AS frequency,
  unit,
  description
from {{TABLE}}
where "carId" = '{{ dataset.carId }}'
group by name
```

* To retrieve the **time series data**

```sql
select time / 1e9 as "timestamp", value
from {{TABLE}}
where "carId" = '{{ dataset.carId }}'
{%- if timestamp_start %}
and CAST({{timestamp_start}} AS BIGINT) * 1e9 <= time
{%- endif %}
{%- if timestamp_stop %}
and CAST({{timestamp_stop}} AS BIGINT)  * 1e9 >= time
{%- endif %}
and name = '{{ signal.name }}'
```
