Vijay B
Vijay B

Reputation: 332

Connect to Databricks SQL endpoint using NodeJS

I am trying to connect to a Databricks SQL endpoint using NodeJS. I followed the instructions on the "Connection Details" tab of my SQL endpoint. As described, I am running Node version 14 or higher, and installed the connector npm package as follows:

npm i @databricks/sql

I used the code provided, included below (I made sure to use the correct host name and access token). I did not change the SQL code from the default (SELECT 1).

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

  var token           = "dapi_MY_ACCESS_TOKEN";
  var server_hostname = "MY_HOSTNAME.cloud.databricks.com";
  var http_path       = "/sql/1.0/endpoints/a8e8b6cfcc6a190f";

  const client = new DBSQLClient();
  const utils  = DBSQLClient.utils;

  client.connect(
    options = {
      token: token,
      host:  server_hostname,
      path:  http_path
    }).then(
      async client => {
        const session = await client.openSession();

        const queryOperation = await session.executeStatement(
          statement = "SELECT 1",
          options   = { runAsync: true });

        await utils.waitUntilReady(
          operation = queryOperation,
          progress  = false,
          callback  = () => {});

        await utils.fetchAll(
          operation = queryOperation
        );

        await queryOperation.close();

        const result = utils.getResult(
          operation = queryOperation
        ).getValue();

        console.table(result);

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

When I run the code, I get the following error message:

node read_databricks.cjs 
TypeError: Cannot read properties of undefined (reading 'waitUntilReady')
    at /Users/vijay.balasubramaniam/test/records-to-cards/read_databricks.cjs:23:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I also tried running the above code within the node REPL, but got the same results. Am I missing a step?

Upvotes: 1

Views: 1707

Answers (1)

amstack
amstack

Reputation: 26

I ran into the same issue.

Delete your package-lock.json. Run npm install and make sure that in the package-lock.json file the version is pointing to beta.1 and not beta.2.

"node_modules/@databricks/sql": {
  "version": "0.1.8-beta.1",
}

Upvotes: 1

Related Questions