Skip to content

Commit 05c729d

Browse files
Sylvestrelibbey-observable
andauthored
Add databricks client and check method (#52)
* added databricks client and check method * server to check * typo * Update lib/config.js Co-authored-by: Libbey White <[email protected]> * Update lib/config.js Co-authored-by: Libbey White <[email protected]> Co-authored-by: Libbey White <[email protected]>
1 parent d6f5534 commit 05c729d

File tree

5 files changed

+135
-3
lines changed

5 files changed

+135
-3
lines changed

lib/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ export function readDecodedConfig(name) {
2626
url: raw.url,
2727
username: raw.username || "", // oracle client requires username
2828
password: raw.password || "", // oracle client requires password
29+
token: raw.token || "", // databricks client requires token
30+
path: raw.path || "", // databricks client requires path
31+
server_host: raw.server_host || "", // databricks client requires server_host
2932
};
3033
} else {
3134
return Object.values(config).map((c) => ({
3235
...decodeSecret(c.secret),
3336
url: c.url,
3437
username: c.username || "", // oracle client requires username
3538
password: c.password || "", // oracle client requires password
39+
token: c.token || "", // databricks client requires token
40+
path: c.path || "", // databricks client requires path
41+
server_host: c.server_host || "", // databricks client requires server_host
3642
}));
3743
}
3844
}

lib/databricks.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
export class DatabricksSingleton {
2+
static instance = null;
3+
4+
constructor() {
5+
throw new Error(
6+
"Do not use new DatabricksSingleton(). Call DatabricksSingleton.initialize() instead."
7+
);
8+
}
9+
static initialize() {
10+
if (!DatabricksSingleton.instance) {
11+
try {
12+
DatabricksSingleton.instance = import("@databricks/sql").then(
13+
(module) => module.default
14+
);
15+
} catch (err) {
16+
console.error(err);
17+
}
18+
}
19+
}
20+
static getInstance() {
21+
if (!DatabricksSingleton.instance)
22+
throw new Error(
23+
"DatabricksSingleton not initialized. Call DatabricksSingleton.initialize() first."
24+
);
25+
return DatabricksSingleton.instance;
26+
}
27+
}
28+
29+
/*
30+
* This function is checking for the validity of the credentials.
31+
* */
32+
export async function check(req, res, connection) {
33+
try {
34+
await connection.openSession();
35+
return {ok: true};
36+
} catch (e) {
37+
throw e;
38+
} finally {
39+
if (connection) {
40+
try {
41+
await connection.close();
42+
} catch (err) {
43+
console.error(err.message);
44+
}
45+
}
46+
}
47+
}
48+
49+
export default ({token, host, path}) => {
50+
DatabricksSingleton.initialize();
51+
return async (req, res) => {
52+
const databricks = await DatabricksSingleton.getInstance();
53+
const client = new databricks.DBSQLClient();
54+
const connection = await client.connect({token, host, path});
55+
56+
// TODO: replace with queryStream method when implemented
57+
return check(req, res, connection);
58+
};
59+
};

lib/server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import postgres from "./postgres.js";
1313
import snowflake from "./snowflake.js";
1414
import mssql from "./mssql.js";
1515
import oracle from "./oracle.js";
16+
import databricks from "./databricks.js";
1617

1718
export async function server(config, argv) {
1819
const development = process.env.NODE_ENV === "development";
@@ -27,6 +28,9 @@ export async function server(config, argv) {
2728
port = 2899,
2829
username,
2930
password,
31+
token,
32+
path,
33+
server_host,
3034
} = config;
3135

3236
const handler =
@@ -40,6 +44,8 @@ export async function server(config, argv) {
4044
? mssql(url)
4145
: type === "oracle"
4246
? await oracle({url, username, password})
47+
: type === "databricks"
48+
? await databricks({token, host: server_host, path})
4349
: null;
4450
if (!handler) {
4551
return exit(`Unknown database type: ${type}`);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"./mysql.js": "./lib/mysql.js",
1212
"./snowflake.js": "./lib/snowflake.js",
1313
"./mssql.js": "./lib/mssql.js",
14-
"./oracle.js": "./lib/oracle.js"
14+
"./oracle.js": "./lib/oracle.js",
15+
"./databricks.js": "./lib/databricks.js"
1516
},
1617
"bin": {
1718
"observable-database-proxy": "./bin/observable-database-proxy.js"
1819
},
1920
"dependencies": {
21+
"@databricks/sql": "^1.0.0",
2022
"JSONStream": "^1.3.5",
2123
"ajv": "^8.11.0",
2224
"micro": "^9.3.4",

yarn.lock

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,17 @@
11191119
enabled "2.0.x"
11201120
kuler "^2.0.0"
11211121

1122+
"@databricks/sql@^1.0.0":
1123+
version "1.0.0"
1124+
resolved "https://registry.yarnpkg.com/@databricks/sql/-/sql-1.0.0.tgz#aa12de5a364c1d15584de9807949e5ac957cef2d"
1125+
integrity sha512-73NVxH0tAVV/u2ns0T3tYpOvvAQ5kTFoQZATHpSlBBQRwTPKmzvHsq+jbpex/wqescoQ6TW9ZRf7W8sO4w2z4g==
1126+
dependencies:
1127+
commander "^9.3.0"
1128+
node-int64 "^0.4.0"
1129+
thrift "^0.16.0"
1130+
uuid "^9.0.0"
1131+
winston "^3.8.2"
1132+
11221133
"@hapi/hoek@^9.0.0":
11231134
version "9.3.0"
11241135
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
@@ -1429,6 +1440,11 @@ async-each@^1.0.1:
14291440
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
14301441
integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==
14311442

1443+
async-limiter@~1.0.0:
1444+
version "1.0.1"
1445+
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
1446+
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
1447+
14321448
async@^3.2.1, async@^3.2.3:
14331449
version "3.2.4"
14341450
resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c"
@@ -1629,6 +1645,11 @@ braces@~3.0.2:
16291645
dependencies:
16301646
fill-range "^7.0.1"
16311647

1648+
browser-or-node@^1.2.1:
1649+
version "1.3.0"
1650+
resolved "https://registry.yarnpkg.com/browser-or-node/-/browser-or-node-1.3.0.tgz#f2a4e8568f60263050a6714b2cc236bb976647a7"
1651+
integrity sha512-0F2z/VSnLbmEeBcUrSuDH5l0HxTXdQQzLjkmBR4cYfvg1zJrKSlmIZFqyFR8oX0NrwPhy3c3HQ6i3OxMbew4Tg==
1652+
16321653
browser-request@^0.3.3:
16331654
version "0.3.3"
16341655
resolved "https://registry.yarnpkg.com/browser-request/-/browser-request-0.3.3.tgz#9ece5b5aca89a29932242e18bf933def9876cc17"
@@ -1918,7 +1939,7 @@ combined-stream@^1.0.8:
19181939
dependencies:
19191940
delayed-stream "~1.0.0"
19201941

1921-
commander@^9.4.0:
1942+
commander@^9.3.0, commander@^9.4.0:
19221943
version "9.4.1"
19231944
resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd"
19241945
integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==
@@ -3262,6 +3283,11 @@ isobject@^3.0.0, isobject@^3.0.1:
32623283
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
32633284
integrity sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==
32643285

3286+
isomorphic-ws@^4.0.1:
3287+
version "4.0.1"
3288+
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc"
3289+
integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==
3290+
32653291
32663292
version "0.16.0"
32673293
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076"
@@ -3805,6 +3831,11 @@ node-fetch@^2.6.7:
38053831
dependencies:
38063832
whatwg-url "^5.0.0"
38073833

3834+
node-int64@^0.4.0:
3835+
version "0.4.0"
3836+
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
3837+
integrity sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==
3838+
38083839
node-releases@^2.0.6:
38093840
version "2.0.6"
38103841
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.6.tgz#8a7088c63a55e493845683ebf3c828d8c51c5503"
@@ -4300,6 +4331,11 @@ python-struct@^1.1.3:
43004331
dependencies:
43014332
long "^4.0.0"
43024333

4334+
q@^1.5.0:
4335+
version "1.5.1"
4336+
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
4337+
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==
4338+
43034339
qs@^6.4.0:
43044340
version "6.11.0"
43054341
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a"
@@ -5060,6 +5096,17 @@ thenify-all@^1.0.0:
50605096
dependencies:
50615097
any-promise "^1.0.0"
50625098

5099+
thrift@^0.16.0:
5100+
version "0.16.0"
5101+
resolved "https://registry.yarnpkg.com/thrift/-/thrift-0.16.0.tgz#6497711610aa32d2f94fc2546f88ee4ff6e4106c"
5102+
integrity sha512-W8DpGyTPlIaK3f+e1XOCLxefaUWXtrOXAaVIDbfYhmVyriYeAKgsBVFNJUV1F9SQ2SPt2sG44AZQxSGwGj/3VA==
5103+
dependencies:
5104+
browser-or-node "^1.2.1"
5105+
isomorphic-ws "^4.0.1"
5106+
node-int64 "^0.4.0"
5107+
q "^1.5.0"
5108+
ws "^5.2.3"
5109+
50635110
"through@>=2.2.7 <3", through@~2.3:
50645111
version "2.3.8"
50655112
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
@@ -5400,6 +5447,11 @@ uuid@^8.3.0:
54005447
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
54015448
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
54025449

5450+
uuid@^9.0.0:
5451+
version "9.0.0"
5452+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
5453+
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==
5454+
54035455
vm2@^3.9.8:
54045456
version "3.9.11"
54055457
resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.11.tgz#a880f510a606481719ec3f9803b940c5805a06fe"
@@ -5490,7 +5542,7 @@ winston-transport@^4.5.0:
54905542
readable-stream "^3.6.0"
54915543
triple-beam "^1.3.0"
54925544

5493-
winston@^3.1.0:
5545+
winston@^3.1.0, winston@^3.8.2:
54945546
version "3.8.2"
54955547
resolved "https://registry.yarnpkg.com/winston/-/winston-3.8.2.tgz#56e16b34022eb4cff2638196d9646d7430fdad50"
54965548
integrity sha512-MsE1gRx1m5jdTTO9Ld/vND4krP2To+lgDoMEHGGa4HIlAUyXJtfc7CxQcGXVyz2IBpw5hbFkj2b/AtUdQwyRew==
@@ -5549,6 +5601,13 @@ write-file-atomic@^2.0.0:
55495601
imurmurhash "^0.1.4"
55505602
signal-exit "^3.0.2"
55515603

5604+
ws@^5.2.3:
5605+
version "5.2.3"
5606+
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.3.tgz#05541053414921bc29c63bee14b8b0dd50b07b3d"
5607+
integrity sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==
5608+
dependencies:
5609+
async-limiter "~1.0.0"
5610+
55525611
xdg-basedir@^3.0.0:
55535612
version "3.0.0"
55545613
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4"

0 commit comments

Comments
 (0)