我正在try 使用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)
我还try 在 node REPL中运行上面的代码,但得到了相同的结果.我是不是漏掉了一步?