SQL CLIENTS & USAGE
CLI
- Download latest cli from trino.io
- Save .trino_config to your
$HOME
folder - Update
.trino_config
with your configurations- set
user
as your API Key - optional - replace the
server
value for a custom HOST
- set
- Run queries as desired
$ trino --execute 'select * from ndaq_rtat10 limit 5'
$ trino --execute 'select * from zacks_hdm limit 5'
Python
- Add requirements.txt in a new project folder, or install those PIP libraries into your existing project.
- Configure environment variables
NASDAQ_DATA_LINK_API_KEY
for your API Key- Optional -
NASDAQ_DATA_LINK_BASE_DOMAIN
for a custom HOST
- Add datalink_sql.py to your project folder
- Run
datalink_sql.py
to invoke sample queries - 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#
- Add DataLinkSQL.csproj in a new project folder, or install those Nuget packages into your existing project.
- Configure environment variables
NASDAQ_DATA_LINK_API_KEY
for your API Key- Optional -
NASDAQ_DATA_LINK_BASE_DOMAIN
for a custom HOST
- Add DataLinkSQL.cs to your project folder
- Run included Main to invoke sample queries
$ dotnet run --property DefineConstants=INCLUDE_MAIN
- 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
- Connect "To a Server" and select "Presto"
- Enter configurations as explained in Endpoints, and also set
- Authentication: Username
- Require SSL: True
- Click the magnifying glass next to the "Enter table name" text box
- 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
- Download the latest driver from trino.io
- Move the driver into a permanent location (where it won't get deleted accidentally); i.e., the DataGrip library folder
- in MacOS, this is
~/Library/Application\ Support/JetBrains/DataGrip${VERSION}/jdbc-drivers/
- in MacOS, this is
- Open DataGrip
- Click: File > New > Driver
- Fill in fields
- Name: Trino 406
- General (tab)
- Driver files: browse and select the downloaded driver
- Class:
io.trino.jdbc.TrinoDriver
- Options (tab)
- Other (section)
- Icon: Trino
- Other (section)
- Click Apply and OK
Set-up Data Source
- Open DataGrip
- Click: File > New > DataSource > Trino 406
- Fill in fields as explained in Endpoints
- Name: DataLink
- General (tab)
- User: your API Key
- URL:
jdbc:trino://${HOST}:${PORT}/${CATALOG}/${SCHEMA}
- Click Apply and OK
Updated 11 months ago