【发布时间】: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