SQL CLIENTS & USAGE

CLI

  1. Download latest cli from trino.io
  2. Save .trino_config to your $HOME folder
  3. Update .trino_config with your configurations
    1. set user as your API Key
    2. optional - replace the server value for a custom HOST
  4. Run queries as desired
$ trino --execute 'select * from ndaq_rtat10 limit 5'
$ trino --execute 'select * from zacks_hdm limit 5'

Python

  1. Add requirements.txt in a new project folder, or install those PIP libraries into your existing project.
  2. Configure environment variables
    1. NASDAQ_DATA_LINK_API_KEY for your API Key
    2. Optional - NASDAQ_DATA_LINK_BASE_DOMAIN for a custom HOST
  3. Add datalink_sql.py to your project folder
  4. Run datalink_sql.py to invoke sample queries
  5. Additionally, create a new module with your desired queries and reuse helper functions
import datalink_sql
import os

connection = datalink_sql.create_connection(os.environ.copy())
sql = "select * from ndaq_rtat"
df = datalink_sql.run_sql(connection, sql)
print(df)

As another example, here is sample Python Code to write directly to disk:

import trino
import csv
import os
 
# save to
fp = "FILENAME.csv"

# env
api_key = os.environ.get("NASDAQ_DATA_LINK_API_KEY")
api_base_domain = os.environ.get(
    "NASDAQ_DATA_LINK_BASE_DOMAIN", "data.nasdaq.com"
)
 
# connect to trino
conn = trino.dbapi.connect(
    host= api_base_domain,
    port=443,
    user=api_key,
    catalog="main",
    schema="huron",
    http_scheme="https",
)
 
# query
sql = """
    select * from ndaq_rtat
    """
 
# run sql
cur = conn.cursor()
 
try:
    results = cur.execute(sql, None)
    # header
    header = [c[0] for c in cur.description]
 
    row_cnt = 0
    with open(fp, "w") as f:
        print(
            "Executing SQL result with Trino and writing results to file on disk..."
        )
        write = csv.writer(f)
        write.writerow(header)
        for row in iter(results):
            write.writerow(row)
            row_cnt += 1
finally:
    cur.close()

📘

NOTE:

Tested with Python 3

DotNet C#

  1. Add DataLinkSQL.csproj in a new project folder, or install those Nuget packages into your existing project.
  2. Configure environment variables
    1. NASDAQ_DATA_LINK_API_KEY for your API Key
    2. Optional - NASDAQ_DATA_LINK_BASE_DOMAIN for a custom HOST
  3. Add DataLinkSQL.cs to your project folder
  4. Run included Main to invoke sample queries
$ dotnet run --property DefineConstants=INCLUDE_MAIN
  1. Additionally, create a new module with your desired queries and reuse helper functions
using NReco.PrestoAdo;
using static DataLinkSQL;

class MyApp
{
    static void Main()
    {
        using (PrestoConnection connection = CreateConnection())
        {
            string sql = "...";
            DbDataReader reader = RunSQL(connection, sql);
            DisplayReader(reader);
        }
    }
}
$ dotnet run

📘

NOTE:

Tested with Python 3

Tableau

  1. Connect "To a Server" and select "Presto"
  2. Enter configurations as explained in Endpoints, and also set
    1. Authentication: Username
    2. Require SSL: True
  3. Click the magnifying glass next to the "Enter table name" text box
  4. You should now see all your tables. Drag and drop them to build your models.

📘

NOTE:

Tested with Tableau Desktop 2022.2

DataGrip

Install JDBC driver

  1. Download the latest driver from trino.io
  2. Move the driver into a permanent location (where it won't get deleted accidentally); i.e., the DataGrip library folder
    1. in MacOS, this is ~/Library/Application\ Support/JetBrains/DataGrip${VERSION}/jdbc-drivers/
  3. Open DataGrip
  4. Click: File > New > Driver
  5. Fill in fields
    1. Name: Trino 406
    2. General (tab)
      1. Driver files: browse and select the downloaded driver
      2. Class: io.trino.jdbc.TrinoDriver
    3. Options (tab)
      1. Other (section)
        1. Icon: Trino
  6. Click Apply and OK

Set-up Data Source

  1. Open DataGrip
  2. Click: File > New > DataSource > Trino 406
  3. Fill in fields as explained in Endpoints
    1. Name: DataLink
    2. General (tab)
      1. User: your API Key
      2. URL: jdbc:trino://${HOST}:${PORT}/${CATALOG}/${SCHEMA}
  4. Click Apply and OK