Databricks client with Unity Catalog and multiple OAuth methods.
import { DatabricksWarehouseClient } from '@lightdash/warehouses';
const client = new DatabricksWarehouseClient({
type: 'databricks',
serverHostName: 'my-workspace.cloud.databricks.com',
httpPath: '/sql/1.0/warehouses/abc123',
database: 'analytics', // Schema name
catalog: 'production', // Unity Catalog (optional)
personalAccessToken: 'dapi1234567890abcdef',
});
await client.test();{ type: 'databricks', personalAccessToken: 'dapi...', ... }{
type: 'databricks',
oauthClientId: 'client-id',
oauthClientSecret: 'client-secret',
authenticationType: 'oauth_m2m',
...
}{
type: 'databricks',
oauthClientId: 'client-id',
refreshToken: 'refresh-token',
authenticationType: 'oauth_u2m',
...
}await client.streamQuery(
'SELECT * FROM production.analytics.sales WHERE date >= "2023-01-01"',
(data) => { /* process rows */ },
{ timezone: 'America/Los_Angeles', tags: {} }
);const tables = await client.getAllTables();
tables.forEach(t => {
console.log(`${t.database}.${t.schema}.${t.table}`);
});import {
exchangeDatabricksOAuthCredentials,
refreshDatabricksOAuthToken,
} from '@lightdash/warehouses';
// Exchange M2M credentials for access token
const tokens = await exchangeDatabricksOAuthCredentials(
'my-workspace.cloud.databricks.com',
'client-id',
'client-secret'
);
// Refresh U2M access token
const refreshed = await refreshDatabricksOAuthToken(
'my-workspace.cloud.databricks.com',
'client-id',
'refresh-token'
);
console.log('New token expires in:', refreshed.expiresIn, 'seconds');import { DatabricksSqlBuilder } from '@lightdash/warehouses';
const builder = new DatabricksSqlBuilder();
builder.getFieldQuoteChar(); // '`'
builder.escapeString("O'Reilly"); // "O\'Reilly"Percentile SQL: Uses PERCENTILE function
// Median: PERCENTILE(col, 0.5)
// 99th: PERCENTILE(col, 0.99)Three-part naming: catalog.schema.table
{
catalog: 'production', // Top-level namespace
database: 'analytics', // Schema (historical naming)
}Uses system metadata tables:
getAllTables(): Queries information_schema.tables for MANAGED tablesgetCatalog(): Queries system.columns in Unity Catalogdatabase field represents schema (historical naming)getAllTables()sql for SQL warehouse access