Building Data Applications on the Lakehouse With the Databricks SQL Driver for Node.js

Engineering


We are excited to announce the general availability of the Databricks SQL Driver for NodeJS. This follows the recent general availability of Databricks SQL Driver for GO and the earlier Databricks SQL Connector for Python. Node.js developers can now easily build data applications on the lakehouse in pure Javascript or TypeScript.

The NodeJS driver offers simple installation and a flexible interface that makes it easy to query data. It also automatically converts data types between Databricks SQL and Node.js clients, removing the need for boilerplate code.

This blog post will use examples of connecting to Databricks and running queries against a sample data set.

Simple installation from npm

With this Node.js driver, there’s no need to deal with ODBC/JDBC driver dependencies. Installation is through npm, which means you can include this connector in your application and use it for CI/CD. On NodeJS 14 or newer:


npm i @databricks/sql

Setting up connection

The connector works with SQL warehouses and All Purpose Clusters. This example shows you how to connect to and run a query on a SQL Warehouse. We import the connector and pass in connection and authentication information to establish a connection. You can authenticate using a Databricks personal access token (PAT) or a Microsoft Azure active directory (AAD) token (to be released shortly).


const { DBSQLClient } = require('@databricks/sql');

const client = new DBSQLClient();

client
  .connect({
    host: '********.databricks.com',
    path: '/sql/1.0/endpoints/****************',
    token: 'dapi********************************',
  })
  .then(async (client) => {
    const session = await client.openSession();

Querying data

The following example retrieves a list of trips from the NYC taxi sample dataset and prints the result to the console.


const queryOperation = await session.executeStatement('SELECT trip_distance FROM samples.nyctaxi.trips', { runAsync: true });
    const result = await queryOperation.fetchAll();
    await queryOperation.close();

    console.table(result);

    await session.close();
    await client.close();
  })
  .catch((error) => {
    console.log(error);
  });

Our documentation includes examples in Javascript and TypeScript to help you get started, as well as the full API reference.

A bright future for Node.js developers on the lakehouse

We’re happy to announce that our Node.js driver is open source on Github. We welcome contributions from the community. We’re already seeing our partners, such as Qlik Analytics, use the Node connector in their products.

We’re even more excited about what our customers will build with the Databricks SQL Driver for Node.js! Please try out the driver and let us know your thoughts on Github. We would love to hear what you would like us to support.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *