簡體   English   中英

使用 NodeJS 連接到 Databricks SQL 端點

[英]Connect to Databricks SQL endpoint using NodeJS

我正在嘗試使用 NodeJS 連接到 Databricks SQL 端點。 我按照我的 SQL 端點的“連接詳細信息”選項卡上的說明進行操作。 如前所述,我運行的是 Node 版本 14 或更高版本,並安裝了連接器 npm package,如下所示:

npm i @databricks/sql

我使用了下面提供的代碼(我確保使用了正確的主機名和訪問令牌)。 我沒有更改默認的 SQL 代碼 (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);
  });

當我運行代碼時,我收到以下錯誤消息:

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)

我還嘗試在節點 REPL 中運行上述代碼,但得到了相同的結果。 我錯過了一步嗎?

我遇到了同樣的問題。

刪除您的package-lock.json 運行npm install並確保在package-lock.json文件中版本指向beta.1而不是beta.2

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM