Skip to content

Conversation

@krinart
Copy link

@krinart krinart commented Aug 21, 2025

What this PR includes:

  • TrinoTableFactory
  • Tests (unit + integration)
  • Example (under examples)
  • Documentation in README

Example:

    let trino_params = to_secret_map(HashMap::from([
        ("host".to_string(), "localhost".to_string()),
        ("port".to_string(), "8080".to_string()),
        ("catalog".to_string(), "tpch".to_string()),
        ("schema".to_string(), "tiny".to_string()),
        ("user".to_string(), "test".to_string()),
        ("sslmode".to_string(), "disabled".to_string()),
    ]));

    let trino_pool = Arc::new(
        TrinoConnectionPool::new(trino_params)
            .await
            .expect("unable to create Trino connection pool"),
    );

    let table_factory = TrinoTableFactory::new(trino_pool.clone());

    let ctx = SessionContext::new();

    ctx.register_table(
        "region",
        table_factory
            .table_provider(TableReference::bare("region"))
            .await
            .expect("failed to register table provider"),
    )
    .expect("failed to register table");

    let df = ctx
        .sql("SELECT * FROM region")
        .await
        .expect("select failed");
    df.show().await.expect("show failed");

Will output:

+-----------+-------------+---------------------------------------------------------------------------------------------------------------------+
| regionkey | name        | comment                                                                                                             |
+-----------+-------------+---------------------------------------------------------------------------------------------------------------------+
| 0         | AFRICA      | lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to  |
| 1         | AMERICA     | hs use ironic, even requests. s                                                                                     |
| 2         | ASIA        | ges. thinly even pinto beans ca                                                                                     |
| 3         | EUROPE      | ly final courts cajole furiously final excuse                                                                       |
| 4         | MIDDLE EAST | uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl        |
+-----------+-------------+---------------------------------------------------------------------------------------------------------------------+

The implemented Trino=>Arrow type mapping

Trino Type Arrow Type
null Null
boolean Boolean
tinyint Int8
smallint Int16
integer Int32
bigint Int64
real Float32
double Float64
varchar Utf8
char Utf8
varbinary Binary
date Date32
time(second) Time32(Millisecond)
time(millisecond) Time32(Millisecond)
time(microsecond) Time64(microsecond)
time(nanosecond) Time64(nanosecond)
timestamp(unit) Timestamp(unit, None)
timestamp(unit) with time zone Timestamp(unit, Some(tz))
decimal(p,s) Decimal(p,s)
numeric(p,s) Decimal(p,s)
array(T) List<T>
row(...) Struct

@krinart krinart marked this pull request as ready for review August 21, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant