Skip to content

Commit 307218c

Browse files
authored
Dune Trino Connector Page V2 (#796)
* Reverting the name changes so that the links work again while I look into the underlying issue. Analytics Studio -> Web App. Analytics API -> SQL API Reference. Catalyst -> Blockchain Integrations. * Adding DBeaver to the list. Adding more SDK samples. Adding more links to the Trino docs. Improving the SEO of the page to rank for terms like dune trino, dune hex, etc. Overall just making the page better for customers.
1 parent 7dc31ba commit 307218c

File tree

4 files changed

+203
-8
lines changed

4 files changed

+203
-8
lines changed

api-reference/overview/dunesql-trino-connector.mdx

Lines changed: 203 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
---
22
title: "DuneSQL Trino Connector"
3-
description: "A convenient way to use Dune outside of Dune with Trino/Presto/Starburst-compatible tools."
3+
description: "Access the entirety of Dune's blockchain data through your preferred Trino/Presto/Starburst-compatible tools and SDKs."
44
icon: "plug"
55
---
66

7-
Access Dune's blockchain data from your favorite BI tools and clients using the DuneSQL Trino/Presto connector. It's a more convenient way to use Dune outside of Dune with any tool that supports Trino, Presto, or Starburst connectors.
7+
Access Dune's blockchain data from your favorite BI tools and clients using the DuneSQL Trino/Presto connector. Connect Dune with popular tools like Hex, Metabase, DBeaver, and any Trino, Presto, or Starburst-compatible application for seamless data analysis.
88

99
<Frame caption="Trino/Presto client → Dune connector → Dune Query Engine">
1010
<img
1111
src="/images/trino-presto-connector/trino - light.png"
12-
alt="Architecture diagram: Trino/Presto client → Dune connector → Dune Query Engine"
12+
alt="Dune Trino Presto connector architecture diagram showing integration flow"
1313
className="block dark:hidden"
1414
noZoom
1515
/>
1616
<img
1717
src="/images/trino-presto-connector/trino - dark.png"
18-
alt="Architecture diagram: Trino/Presto client → Dune connector → Dune Query Engine"
18+
alt="Dune Trino Presto connector architecture diagram showing integration flow"
1919
className="hidden dark:block"
2020
noZoom
2121
/>
2222
</Frame>
2323

2424
## Compatible Tools
2525

26-
Use any tool that supports Trino, Presto, or Starburst connectors. Popular choices include:
26+
Dune's Trino connector supports any tool that works with Trino, Presto, or Starburst connectors. Popular Dune integrations include:
2727

2828
<CardGroup cols={2}>
2929
<Card title="Hex" icon="cube" iconType="duotone" href="#hex-setup-for-dune">
30-
Notebook-native analytics; connect via built-in Trino connector.
30+
Connect Dune to Hex's notebook-native analytics via built-in Trino connector.
3131
</Card>
3232
<Card
3333
title="Metabase"
3434
icon="chart-bar"
3535
iconType="duotone"
3636
href="#metabase-setup-for-dune"
3737
>
38-
Self-hosted/managed BI; connect using the Starburst/Trino driver.
38+
Integrate Dune with Metabase using the Starburst/Trino driver for BI dashboards.
39+
</Card>
40+
<Card
41+
title="DBeaver"
42+
icon="database"
43+
iconType="duotone"
44+
href="#dbeaver-setup-for-dune"
45+
>
46+
Connect Dune to DBeaver using the Trino driver for direct SQL access to blockchain data.
3947
</Card>
4048
<Card
4149
title="Any Trino/Presto/Starburst client"
@@ -48,6 +56,10 @@ Use any tool that supports Trino, Presto, or Starburst connectors. Popular choic
4856
</Card>
4957
</CardGroup>
5058

59+
<Note>
60+
Any of the supported client applications listed in the [Trino ecosystem](https://trino.io/ecosystem/#official-client-applications) are supported. Please visit their documentation to learn about their specific connection instructions, though the configuration should generally follow the same pattern using the connection parameters below.
61+
</Note>
62+
5163
## Connection Parameters
5264

5365
Use these values in your Trino, Presto, or Starburst client configuration:
@@ -184,7 +196,7 @@ Follow these steps to connect Dune as a data source in Metabase.
184196
<Note>
185197
Schema discovery queries such as <code>SHOW TABLES</code> or{" "}
186198
<code>SHOW SCHEMAS</code> may not be available in Metabase with this connector
187-
because Dunes catalog spans millions of tables. Many BI tools are not yet
199+
because Dune's catalog spans millions of tables. Many BI tools are not yet
188200
optimized to enumerate catalogs at this scale. An update with improved schema
189201
discovery is planned for the future.
190202
</Note>
@@ -218,6 +230,74 @@ WHERE block_time > now() - interval '12' month
218230
GROUP BY 1
219231
ORDER BY 1 DESC
220232
```
233+
234+
## DBeaver Setup for Dune
235+
236+
Follow these steps to connect Dune as a data source in DBeaver.
237+
238+
### Add a Database Connection
239+
240+
<Steps>
241+
<Step title="Create new connection">
242+
In DBeaver, click the <b>New Database Connection</b> button. It usually looks like a plug with a plus on it.
243+
</Step>
244+
<Step title="Select Trino database">
245+
You'll be taken to the "Connect to a database" screen. Find and select <b>Trino</b> from the list of accepted databases, then click on it.
246+
<Frame>
247+
<img
248+
src="/images/trino-presto-connector/dbeaver-1.png"
249+
alt="DBeaver step 2: Select Trino from database list"
250+
/>
251+
</Frame>
252+
</Step>
253+
<Step title="Configure connection details">
254+
You'll be taken to a screen where you can fill in your connection details. Make sure to click <b>Connect by host</b>, then fill in the connection parameters using the values from the <a href="#connection-parameters">Connection Parameters</a> section.
255+
<Frame>
256+
<img
257+
src="/images/trino-presto-connector/dbeaver-2.png"
258+
alt="DBeaver step 3: Enter connection details"
259+
/>
260+
</Frame>
261+
</Step>
262+
<Step title="Finish connection setup">
263+
Once you have all the details filled out properly, click <b>Finish</b> to create the connection.
264+
</Step>
265+
</Steps>
266+
267+
### Run a Test Query
268+
269+
After configuring your connection, you can run a query to verify that everything is working.
270+
271+
<Steps>
272+
<Step title="Open SQL editor">
273+
Right-click on your Dune database connection and navigate to the <b>SQL Editor</b> section. This will open up a new SQL editor.
274+
</Step>
275+
<Step title="Write your SQL query">
276+
In the SQL editor, you can write all of your Dune-compatible SQL. Paste the example query below into the editor.
277+
</Step>
278+
<Step title="Run the script">
279+
Click the <b>Run</b> button to execute your script. If everything went well, you will see the results displayed in the results panel.
280+
<Frame>
281+
<img
282+
src="/images/trino-presto-connector/dbeaver-3.png"
283+
alt="DBeaver step 5: Run SQL script and view results"
284+
/>
285+
</Frame>
286+
</Step>
287+
</Steps>
288+
289+
You can use this query to test your connection. It fetches the daily transaction count from the last year on Base.
290+
291+
```sql
292+
SELECT
293+
date_trunc('day', block_time) AS time,
294+
count(*) AS count
295+
FROM base.transactions
296+
WHERE block_time > now() - interval '12' month
297+
GROUP BY 1
298+
ORDER BY 1 DESC
299+
```
300+
221301
## Using Trino SDKs directly in your code
222302

223303
Connect to Dune using Trino SDKs in your preferred language.
@@ -271,10 +351,125 @@ Connect to Dune using Trino SDKs in your preferred language.
271351
cursor.execute("SELECT count(*) FROM base.transactions WHERE block_time > now() - interval '1' day")
272352
print(cursor.fetchall())
273353
```
354+
</Tab>
355+
356+
<Tab title="Rust">
357+
```rust
358+
use prusto::{ClientBuilder, Presto};
359+
360+
#[derive(Presto, Debug)]
361+
struct Foo {
362+
a: i64,
363+
b: f64,
364+
c: String,
365+
}
366+
367+
#[tokio::main]
368+
async fn main() {
369+
let cli = ClientBuilder::new("user", "localhost")
370+
.port(8090)
371+
.catalog("catalog")
372+
.build()
373+
.unwrap();
374+
375+
let sql = "select 1 as a, cast(1.1 as double) as b, 'bar' as c ";
376+
377+
let data = cli.get_all::<Foo>(sql.into()).await.unwrap().into_vec();
378+
379+
for r in data {
380+
println!("{:?}", r)
381+
}
382+
}
383+
```
384+
</Tab>
274385

386+
<Tab title="Go">
387+
```go
388+
import "database/sql"
389+
import _ "github.com/trinodb/trino-go-client/trino"
390+
391+
dsn := "http://user@localhost:8080?catalog=default&schema=test"
392+
db, err := sql.Open("trino", dsn)
393+
```
394+
</Tab>
395+
396+
<Tab title="Ruby">
397+
```ruby
398+
require 'trino-client'
399+
400+
# create a client object:
401+
client = Trino::Client.new(
402+
server: "localhost:8880", # required option
403+
ssl: {verify: false},
404+
catalog: "native",
405+
schema: "default",
406+
user: "frsyuki",
407+
password: "********",
408+
time_zone: "US/Pacific",
409+
language: "English",
410+
properties: {
411+
"hive.force_local_scheduling": true,
412+
"raptor.reader_stream_buffer_size": "32MB"
413+
},
414+
http_proxy: "proxy.example.com:8080",
415+
http_debug: true
416+
)
417+
418+
# run a query and get results as an array of arrays:
419+
columns, rows = client.run("select * from sys.node")
420+
rows.each {|row|
421+
p row # row is an array
422+
}
423+
424+
# run a query and get results as an array of hashes:
425+
results = client.run_with_names("select alpha, 1 AS beta from tablename")
426+
results.each {|row|
427+
p row['alpha'] # access by name
428+
p row['beta']
429+
p row.values[0] # access by index
430+
p row.values[1]
431+
}
432+
433+
# run a query and fetch results streamingly:
434+
client.query("select * from sys.node") do |q|
435+
# get columns:
436+
q.columns.each {|column|
437+
puts "column: #{column.name}.#{column.type}"
438+
}
439+
440+
# get query results. it feeds more rows until
441+
# query execution finishes:
442+
q.each_row {|row|
443+
p row # row is an array
444+
}
445+
end
446+
447+
# killing a query
448+
query = client.query("select * from sys.node")
449+
query_id = query.query_info.query_id
450+
query.each_row {|row| ... } # when a thread is processing the query,
451+
client.kill(query_id) # another thread / process can kill the query.
452+
453+
# Use Query#transform_row to parse Trino ROW types into Ruby Hashes.
454+
# You can also set a scalar_parser to parse scalars how you'd like them.
455+
scalar_parser = -> (data, type) { (type === 'json') ? JSON.parse(data) : data }
456+
client.query("select * from sys.node") do |q|
457+
q.scalar_parser = scalar_parser
458+
459+
# get query results. it feeds more rows until
460+
# query execution finishes:
461+
q.each_row {|row|
462+
p q.transform_row(row)
463+
}
464+
end
465+
```
275466
</Tab>
276467
</Tabs>
277468

469+
<Note>
470+
Besides the code samples shown above, Trino supports a variety of other official and unofficial SDKs. Please check the [official Trino SDKs page](https://trino.io/ecosystem/client-driver#official-client-drivers) to see which ones are available and to view their GitHub repositories for updated code samples and documentation.
471+
</Note>
472+
278473
## Supported SQL Operations
279474

280475
Queries executed via the connector align with what you can run on the Dune platform. See the [Query Engine overview](/query-engine/overview) for more information on supported functions and syntax.
1.01 MB
Loading
481 KB
Loading
982 KB
Loading

0 commit comments

Comments
 (0)