or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bigquery-client.mdclickhouse-client.mdcore-types.mdcredentials.mddatabricks-client.mdfactory-functions.mdindex.mdpostgres-client.mdredshift-client.mdsnowflake-client.mdsql-builders.mdssh-tunnel.mdtrino-client.md
tile.json

databricks-client.mddocs/

Databricks Client

Databricks client with Unity Catalog and multiple OAuth methods.

Quick Start

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();

Key Features

  • Unity Catalog: Three-part naming (catalog.schema.table)
  • Multiple Auth: Personal tokens, OAuth M2M, OAuth U2M
  • SQL Warehouse Integration: Via HTTP path
  • Timezone Support: Session-level configuration

Authentication Methods

Personal Access Token

{ type: 'databricks', personalAccessToken: 'dapi...', ... }

OAuth M2M (Machine-to-Machine)

{
  type: 'databricks',
  oauthClientId: 'client-id',
  oauthClientSecret: 'client-secret',
  authenticationType: 'oauth_m2m',
  ...
}

OAuth U2M (User-to-Machine)

{
  type: 'databricks',
  oauthClientId: 'client-id',
  refreshToken: 'refresh-token',
  authenticationType: 'oauth_u2m',
  ...
}

Common Patterns

Query with Timezone

await client.streamQuery(
  'SELECT * FROM production.analytics.sales WHERE date >= "2023-01-01"',
  (data) => { /* process rows */ },
  { timezone: 'America/Los_Angeles', tags: {} }
);

Get Tables with Unity Catalog

const tables = await client.getAllTables();
tables.forEach(t => {
  console.log(`${t.database}.${t.schema}.${t.table}`);
});

OAuth Helper Functions

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');

SQL Builder

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)

Unity Catalog

Three-part naming: catalog.schema.table

{
  catalog: 'production', // Top-level namespace
  database: 'analytics', // Schema (historical naming)
}

Metadata Operations

Uses system metadata tables:

  • getAllTables(): Queries information_schema.tables for MANAGED tables
  • getCatalog(): Queries system.columns in Unity Catalog

Notes

  • database field represents schema (historical naming)
  • Only MANAGED tables returned by getAllTables()
  • Spark SQL compatible
  • OAuth scope: always sql for SQL warehouse access