【问题标题】:Connect to Databricks SQL endpoint using NodeJS使用 NodeJS 连接到 Databricks SQL 端点
【发布时间】:2022-10-04 22:01:12
【问题描述】:

我正在尝试使用 NodeJS 连接到 Databricks SQL 端点。我按照我的 SQL 端点的“连接详细信息”选项卡上的说明进行操作。如前所述,我正在运行 Node 版本 14 或更高版本,并安装了连接器 npm 包,如下所示:

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 中运行上述代码,但得到了相同的结果。我错过了一步吗?

【问题讨论】:

    标签: sql node.js databricks


    【解决方案1】:

    我遇到了同样的问题。删除你的 package-lock.json。运行 npm install 并确保在 package-lock.json 文件中版本指向 beta.1 而不是 bate.2。

    “node_modules/@databricks/sql”:{ “版本”:“0.1.8-beta.1”,

    【讨论】:

      猜你喜欢
      • 2022-06-12
      • 2020-05-22
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 2018-08-11
      • 1970-01-01
      相关资源
      最近更新 更多