Skip to main content

Crate trino_rust_client

Crate trino_rust_client 

Source
Expand description

An async Trino client.

Build a Client with ClientBuilder, then run queries. Rows deserialize into a #[derive(Trino)] struct for statically-known schemas, or into Row when the shape is only known at runtime.

§Quickstart

use trino_rust_client::{client::ClientBuilder, Trino};
use futures::StreamExt;
use serde::{Deserialize, Serialize};

// A result row type needs `Trino` (column mapping) plus serde's derives.
#[derive(Trino, Debug, Deserialize, Serialize)]
struct Nation {
    nationkey: i64,
    name: String,
}

let client = ClientBuilder::new("user", "localhost")
    .port(8080)
    .catalog("tpch")
    .schema("sf1")
    .build()?;

// Buffer the whole result set:
let nations = client.get_all::<Nation>("SELECT nationkey, name FROM nation").await?;
for n in nations.as_slice() {
    println!("{n:?}");
}

// …or stream it lazily, without holding the whole result in memory:
let mut rows = client.stream::<Nation>("SELECT nationkey, name FROM nation").await?;
while let Some(row) = rows.next().await {
    println!("{:?}", row?);
}

§Result types

  • #[derive(Trino)] structs — decode columns by name into typed fields.
  • Row — a dynamically-typed row when the schema is not known at compile time; pair it with DataSet to keep the column metadata.

§Error handling

All fallible calls return error::Error. A query failure from the coordinator is error::Error::Query; match on QueryError::kind for common cases such as TableNotFound. See the error module for details.

§Cargo features

  • spooling — support Trino’s spooling protocol for large result sets (segments fetched from object storage), enabling ClientBuilder::spooling_encoding and related options.

§Observability

The client emits tracing events and wraps each query in a span carrying its query_id. Install any tracing subscriber to see them.

Upgrading across a breaking release? See the migration guide.

Re-exports§

pub use client::*;
pub use models::*;
pub use types::*;

Modules§

auth
client
error
models
retry
selected_role
session
spooling
ssl
transaction
tuples
types

Derive Macros§

Trino
Derive macro to parse and represent a Trino result table.