Trino distributed SQL engine client with BasicAuth.
import { TrinoWarehouseClient } from '@lightdash/warehouses';
const client = new TrinoWarehouseClient({
type: 'trino',
host: 'trino.example.com',
port: 8080,
user: 'analyst',
password: 'mypassword',
dbname: 'hive', // Catalog name
schema: 'default',
http_scheme: 'https',
});
await client.test();await client.streamQuery(
`SELECT
customer_id,
SUM(order_amount) as total
FROM hive.default.orders
WHERE order_date >= DATE '2023-01-01'
GROUP BY customer_id`,
(data) => {
// Column names are lowercase
data.rows.forEach(row => {
console.log(`Customer ${row.customer_id}: $${row.total}`);
});
},
{ timezone: 'America/New_York', tags: {} }
);await client.streamQuery(
`SELECT h.user_id, p.email
FROM hive.sales.users h
JOIN postgresql.public.profiles p ON h.user_id = p.id`,
(data) => { /* process */ },
{ tags: {} }
);import { TrinoSqlBuilder } from '@lightdash/warehouses';
const builder = new TrinoSqlBuilder();
builder.getFieldQuoteChar(); // '"'
builder.getFloatingType(); // 'DOUBLE'
builder.escapeString("O'Reilly"); // "O''Reilly"Percentile SQL: Uses APPROX_PERCENTILE (approximate)
// Median: APPROX_PERCENTILE(col, 0.5)
// 95th: APPROX_PERCENTILE(col, 0.95)import { TrinoTypes } from '@lightdash/warehouses';
enum TrinoTypes {
BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT,
REAL, DOUBLE, DECIMAL, VARCHAR, CHAR, VARBINARY, JSON,
DATE, TIME, TIME_TZ, TIMESTAMP, TIMESTAMP_TZ,
ARRAY, MAP, ROW, IPADDRESS, UUID,
}Set via X-Trino-Session HTTP header:
{ timezone: 'America/New_York' }Important: All column names normalized to lowercase for Snowflake compatibility.
getAllTables(): Filters out information_schema and system schemasinformation_schema.columns for catalog queriescatalog.schema.table