@databricks/sql 0.1.8-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/.gitattributes +32 -0
  2. package/CHANGELOG.md +1 -0
  3. package/CONTRIBUTING.md +55 -0
  4. package/LICENSE +201 -0
  5. package/README.md +78 -0
  6. package/dist/DBSQLClient.d.ts +42 -0
  7. package/dist/DBSQLClient.js +111 -0
  8. package/dist/DBSQLClient.js.map +1 -0
  9. package/dist/HiveClient.d.ts +35 -0
  10. package/dist/HiveClient.js +156 -0
  11. package/dist/HiveClient.js.map +1 -0
  12. package/dist/HiveOperation.d.ts +65 -0
  13. package/dist/HiveOperation.js +190 -0
  14. package/dist/HiveOperation.js.map +1 -0
  15. package/dist/HiveSession.d.ts +30 -0
  16. package/dist/HiveSession.js +197 -0
  17. package/dist/HiveSession.js.map +1 -0
  18. package/dist/connection/auth/NoSaslAuthentication.d.ts +5 -0
  19. package/dist/connection/auth/NoSaslAuthentication.js +15 -0
  20. package/dist/connection/auth/NoSaslAuthentication.js.map +1 -0
  21. package/dist/connection/auth/PlainHttpAuthentication.d.ts +15 -0
  22. package/dist/connection/auth/PlainHttpAuthentication.js +30 -0
  23. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -0
  24. package/dist/connection/auth/helpers/SaslPackageFactory.d.ts +11 -0
  25. package/dist/connection/auth/helpers/SaslPackageFactory.js +24 -0
  26. package/dist/connection/auth/helpers/SaslPackageFactory.js.map +1 -0
  27. package/dist/connection/connections/HttpConnection.d.ts +13 -0
  28. package/dist/connection/connections/HttpConnection.js +77 -0
  29. package/dist/connection/connections/HttpConnection.js.map +1 -0
  30. package/dist/connection/contracts/IAuthentication.d.ts +4 -0
  31. package/dist/connection/contracts/IAuthentication.js +3 -0
  32. package/dist/connection/contracts/IAuthentication.js.map +1 -0
  33. package/dist/connection/contracts/IConnectionOptions.d.ts +23 -0
  34. package/dist/connection/contracts/IConnectionOptions.js +3 -0
  35. package/dist/connection/contracts/IConnectionOptions.js.map +1 -0
  36. package/dist/connection/contracts/IConnectionProvider.d.ts +6 -0
  37. package/dist/connection/contracts/IConnectionProvider.js +3 -0
  38. package/dist/connection/contracts/IConnectionProvider.js.map +1 -0
  39. package/dist/connection/contracts/IThriftConnection.d.ts +4 -0
  40. package/dist/connection/contracts/IThriftConnection.js +3 -0
  41. package/dist/connection/contracts/IThriftConnection.js.map +1 -0
  42. package/dist/connection/contracts/ITransport.d.ts +13 -0
  43. package/dist/connection/contracts/ITransport.js +3 -0
  44. package/dist/connection/contracts/ITransport.js.map +1 -0
  45. package/dist/connection/transports/HttpTransport.d.ts +14 -0
  46. package/dist/connection/transports/HttpTransport.js +39 -0
  47. package/dist/connection/transports/HttpTransport.js.map +1 -0
  48. package/dist/connection/types/AuthOptions.d.ts +4 -0
  49. package/dist/connection/types/AuthOptions.js +3 -0
  50. package/dist/connection/types/AuthOptions.js.map +1 -0
  51. package/dist/contracts/IHiveClient.d.ts +10 -0
  52. package/dist/contracts/IHiveClient.js +3 -0
  53. package/dist/contracts/IHiveClient.js.map +1 -0
  54. package/dist/contracts/IHiveSession.d.ts +126 -0
  55. package/dist/contracts/IHiveSession.js +3 -0
  56. package/dist/contracts/IHiveSession.js.map +1 -0
  57. package/dist/contracts/IOperation.d.ts +47 -0
  58. package/dist/contracts/IOperation.js +3 -0
  59. package/dist/contracts/IOperation.js.map +1 -0
  60. package/dist/dto/InfoValue.d.ts +9 -0
  61. package/dist/dto/InfoValue.js +31 -0
  62. package/dist/dto/InfoValue.js.map +1 -0
  63. package/dist/dto/Status.d.ts +15 -0
  64. package/dist/dto/Status.js +21 -0
  65. package/dist/dto/Status.js.map +1 -0
  66. package/dist/errors/AuthenticationError.d.ts +3 -0
  67. package/dist/errors/AuthenticationError.js +30 -0
  68. package/dist/errors/AuthenticationError.js.map +1 -0
  69. package/dist/errors/HiveDriverError.d.ts +2 -0
  70. package/dist/errors/HiveDriverError.js +26 -0
  71. package/dist/errors/HiveDriverError.js.map +1 -0
  72. package/dist/errors/OperationStateError.d.ts +6 -0
  73. package/dist/errors/OperationStateError.js +32 -0
  74. package/dist/errors/OperationStateError.js.map +1 -0
  75. package/dist/errors/StatusError.d.ts +8 -0
  76. package/dist/errors/StatusError.js +15 -0
  77. package/dist/errors/StatusError.js.map +1 -0
  78. package/dist/factory/StatusFactory.d.ts +14 -0
  79. package/dist/factory/StatusFactory.js +40 -0
  80. package/dist/factory/StatusFactory.js.map +1 -0
  81. package/dist/hive/Commands/BaseCommand.d.ts +7 -0
  82. package/dist/hive/Commands/BaseCommand.js +36 -0
  83. package/dist/hive/Commands/BaseCommand.js.map +1 -0
  84. package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +12 -0
  85. package/dist/hive/Commands/CancelDelegationTokenCommand.js +34 -0
  86. package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -0
  87. package/dist/hive/Commands/CancelOperationCommand.d.ts +11 -0
  88. package/dist/hive/Commands/CancelOperationCommand.js +34 -0
  89. package/dist/hive/Commands/CancelOperationCommand.js.map +1 -0
  90. package/dist/hive/Commands/CloseOperationCommand.d.ts +11 -0
  91. package/dist/hive/Commands/CloseOperationCommand.js +34 -0
  92. package/dist/hive/Commands/CloseOperationCommand.js.map +1 -0
  93. package/dist/hive/Commands/CloseSessionCommand.d.ts +11 -0
  94. package/dist/hive/Commands/CloseSessionCommand.js +34 -0
  95. package/dist/hive/Commands/CloseSessionCommand.js.map +1 -0
  96. package/dist/hive/Commands/ExecuteStatementCommand.d.ts +17 -0
  97. package/dist/hive/Commands/ExecuteStatementCommand.js +34 -0
  98. package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -0
  99. package/dist/hive/Commands/FetchResultsCommand.d.ts +20 -0
  100. package/dist/hive/Commands/FetchResultsCommand.js +34 -0
  101. package/dist/hive/Commands/FetchResultsCommand.js.map +1 -0
  102. package/dist/hive/Commands/GetCatalogsCommand.d.ts +12 -0
  103. package/dist/hive/Commands/GetCatalogsCommand.js +34 -0
  104. package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -0
  105. package/dist/hive/Commands/GetColumnsCommand.d.ts +16 -0
  106. package/dist/hive/Commands/GetColumnsCommand.js +34 -0
  107. package/dist/hive/Commands/GetColumnsCommand.js.map +1 -0
  108. package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +18 -0
  109. package/dist/hive/Commands/GetCrossReferenceCommand.js +34 -0
  110. package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -0
  111. package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +14 -0
  112. package/dist/hive/Commands/GetDelegationTokenCommand.js +34 -0
  113. package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -0
  114. package/dist/hive/Commands/GetFunctionsCommand.d.ts +15 -0
  115. package/dist/hive/Commands/GetFunctionsCommand.js +34 -0
  116. package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -0
  117. package/dist/hive/Commands/GetInfoCommand.d.ts +16 -0
  118. package/dist/hive/Commands/GetInfoCommand.js +34 -0
  119. package/dist/hive/Commands/GetInfoCommand.js.map +1 -0
  120. package/dist/hive/Commands/GetOperationStatusCommand.d.ts +23 -0
  121. package/dist/hive/Commands/GetOperationStatusCommand.js +34 -0
  122. package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -0
  123. package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +15 -0
  124. package/dist/hive/Commands/GetPrimaryKeysCommand.js +34 -0
  125. package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -0
  126. package/dist/hive/Commands/GetQueryIdCommand.d.ts +11 -0
  127. package/dist/hive/Commands/GetQueryIdCommand.js +34 -0
  128. package/dist/hive/Commands/GetQueryIdCommand.js.map +1 -0
  129. package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +12 -0
  130. package/dist/hive/Commands/GetResultSetMetadataCommand.js +34 -0
  131. package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -0
  132. package/dist/hive/Commands/GetSchemasCommand.d.ts +14 -0
  133. package/dist/hive/Commands/GetSchemasCommand.js +34 -0
  134. package/dist/hive/Commands/GetSchemasCommand.js.map +1 -0
  135. package/dist/hive/Commands/GetTableTypesCommand.d.ts +12 -0
  136. package/dist/hive/Commands/GetTableTypesCommand.js +34 -0
  137. package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -0
  138. package/dist/hive/Commands/GetTablesCommand.d.ts +16 -0
  139. package/dist/hive/Commands/GetTablesCommand.js +34 -0
  140. package/dist/hive/Commands/GetTablesCommand.js.map +1 -0
  141. package/dist/hive/Commands/GetTypeInfoCommand.d.ts +12 -0
  142. package/dist/hive/Commands/GetTypeInfoCommand.js +34 -0
  143. package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -0
  144. package/dist/hive/Commands/OpenSessionCommand.d.ts +33 -0
  145. package/dist/hive/Commands/OpenSessionCommand.js +34 -0
  146. package/dist/hive/Commands/OpenSessionCommand.js.map +1 -0
  147. package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +12 -0
  148. package/dist/hive/Commands/RenewDelegationTokenCommand.js +34 -0
  149. package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -0
  150. package/dist/hive/Commands/SetClientInfoCommand.d.ts +12 -0
  151. package/dist/hive/Commands/SetClientInfoCommand.js +34 -0
  152. package/dist/hive/Commands/SetClientInfoCommand.js.map +1 -0
  153. package/dist/hive/HiveDriver.d.ts +52 -0
  154. package/dist/hive/HiveDriver.js +129 -0
  155. package/dist/hive/HiveDriver.js.map +1 -0
  156. package/dist/hive/Types/index.d.ts +229 -0
  157. package/dist/hive/Types/index.js +16 -0
  158. package/dist/hive/Types/index.js.map +1 -0
  159. package/dist/index.d.ts +25 -0
  160. package/dist/index.js +67 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/result/IOperationResult.d.ts +5 -0
  163. package/dist/result/IOperationResult.js +3 -0
  164. package/dist/result/IOperationResult.js.map +1 -0
  165. package/dist/result/JsonResult.d.ts +20 -0
  166. package/dist/result/JsonResult.js +137 -0
  167. package/dist/result/JsonResult.js.map +1 -0
  168. package/dist/result/NullResult.d.ts +6 -0
  169. package/dist/result/NullResult.js +13 -0
  170. package/dist/result/NullResult.js.map +1 -0
  171. package/dist/utils/GetResult.d.ts +16 -0
  172. package/dist/utils/GetResult.js +38 -0
  173. package/dist/utils/GetResult.js.map +1 -0
  174. package/dist/utils/HiveUtils.d.ts +11 -0
  175. package/dist/utils/HiveUtils.js +39 -0
  176. package/dist/utils/HiveUtils.js.map +1 -0
  177. package/dist/utils/ProgressUpdateTransformer.d.ts +8 -0
  178. package/dist/utils/ProgressUpdateTransformer.js +33 -0
  179. package/dist/utils/ProgressUpdateTransformer.js.map +1 -0
  180. package/dist/utils/WaitUntilReady.d.ts +16 -0
  181. package/dist/utils/WaitUntilReady.js +120 -0
  182. package/dist/utils/WaitUntilReady.js.map +1 -0
  183. package/docs/readme.md +227 -0
  184. package/docs/troubleshooting.md +84 -0
  185. package/examples/data_types.js +173 -0
  186. package/examples/repl +106 -0
  187. package/examples/session.js +55 -0
  188. package/examples/usage.js +18 -0
  189. package/nyc.config.js +8 -0
  190. package/package.json +56 -0
  191. package/tests/e2e/data_types.test.js +353 -0
  192. package/tests/e2e/utils/config.js +20 -0
  193. package/tests/e2e/utils/logger.js +22 -0
  194. package/tests/unit/HiveClient.test.js +153 -0
  195. package/tests/unit/HiveOperation.test.js +340 -0
  196. package/tests/unit/HiveSession.test.js +146 -0
  197. package/tests/unit/connection/auth/PlainHttpAuthentication.test.js +44 -0
  198. package/tests/unit/connection/connections/HttpConnection.test.js +141 -0
  199. package/tests/unit/dto/InfoValue.test.js +50 -0
  200. package/tests/unit/factory/StatusFactory.test.js +62 -0
  201. package/tests/unit/hive/HiveDriver.test.js +115 -0
  202. package/tests/unit/hive/commands/CancelDelegationTokenCommand.test.js +43 -0
  203. package/tests/unit/hive/commands/CancelOperationCommand.test.js +45 -0
  204. package/tests/unit/hive/commands/CloseOperationCommand.test.js +45 -0
  205. package/tests/unit/hive/commands/CloseSessionCommand.test.js +38 -0
  206. package/tests/unit/hive/commands/ExecuteStatementCommand.test.js +54 -0
  207. package/tests/unit/hive/commands/FetchResultsCommand.test.js +59 -0
  208. package/tests/unit/hive/commands/GetCatalogsCommand.test.js +50 -0
  209. package/tests/unit/hive/commands/GetColumnsCommand.test.js +50 -0
  210. package/tests/unit/hive/commands/GetCrossReferenceCommand.test.js +56 -0
  211. package/tests/unit/hive/commands/GetDelegationTokenCommand.test.js +45 -0
  212. package/tests/unit/hive/commands/GetFunctionsCommand.test.js +50 -0
  213. package/tests/unit/hive/commands/GetInfoCommand.test.js +51 -0
  214. package/tests/unit/hive/commands/GetOperationStatusCommand.test.js +63 -0
  215. package/tests/unit/hive/commands/GetPrimaryKeysCommand.test.js +50 -0
  216. package/tests/unit/hive/commands/GetQueryIdCommand.test.js +42 -0
  217. package/tests/unit/hive/commands/GetResultSetMetadataCommand.test.js +54 -0
  218. package/tests/unit/hive/commands/GetSchemasCommand.test.js +52 -0
  219. package/tests/unit/hive/commands/GetTableTypesCommand.test.js +50 -0
  220. package/tests/unit/hive/commands/GetTablesCommand.test.js +54 -0
  221. package/tests/unit/hive/commands/GetTypeInfoCommand.test.js +50 -0
  222. package/tests/unit/hive/commands/OpenSessionCommand.test.js +43 -0
  223. package/tests/unit/hive/commands/RenewDelegationTokenCommand.test.js +43 -0
  224. package/tests/unit/hive/commands/SetClientInfoCommand.test.js +45 -0
  225. package/tests/unit/result/JsonResult.test.js +295 -0
  226. package/tests/unit/utils/GetResult.test.js +30 -0
  227. package/tests/unit/utils/HiveUtils.test.js +60 -0
  228. package/tests/unit/utils/ProgressUpdateTransformer.test.js +28 -0
  229. package/tests/unit/utils/WaitUntilReady.test.js +105 -0
  230. package/thrift/TCLIService.thrift +1299 -0
  231. package/thrift/gen-nodejs/TCLIService.js +4596 -0
  232. package/thrift/gen-nodejs/TCLIService_types.js +6794 -0
  233. package/tsconfig.json +13 -0
package/examples/repl ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { DBSQLClient } = require('..');
4
+ const repl = require('node:repl');
5
+ const { Console } = require('node:console');
6
+ const { Transform } = require('node:stream');
7
+ const { program } = require('commander');
8
+
9
+ const ts = new Transform({ transform(chunk, enc, cb) { cb(null, chunk) } })
10
+ const logger = new Console({ stdout: ts })
11
+
12
+ async function initClient({ host, endpointId, token }) {
13
+ const client = new DBSQLClient();
14
+ return client.connect({
15
+ host,
16
+ path: `/sql/1.0/endpoints/${endpointId}`,
17
+ token,
18
+ });
19
+ }
20
+
21
+ async function runQuery(session, query) {
22
+ const utils = DBSQLClient.utils;
23
+
24
+ const queryOperation = await session.executeStatement(query, { runAsync: true });
25
+ await utils.waitUntilReady(queryOperation, false, () => {});
26
+ await utils.fetchAll(queryOperation);
27
+ await queryOperation.close();
28
+
29
+ return utils.getResult(queryOperation).getValue();
30
+ }
31
+
32
+ const format = {
33
+ reset: '\x1b[0m',
34
+ bold: '\x1b[1m',
35
+
36
+ fg: {
37
+ black: '\x1b[30m',
38
+ red: '\x1b[31m',
39
+ green: '\x1b[32m',
40
+ yellow: '\x1b[33m',
41
+ blue: '\x1b[34m',
42
+ magenta: '\x1b[35m',
43
+ cyan: '\x1b[36m',
44
+ white: '\x1b[37m',
45
+ },
46
+
47
+ bg: {
48
+ black: '\x1b[40m',
49
+ red: '\x1b[41m',
50
+ green: '\x1b[42m',
51
+ yellow: '\x1b[43m',
52
+ blue: '\x1b[44m',
53
+ magenta: '\x1b[45m',
54
+ cyan: '\x1b[46m',
55
+ white: '\x1b[47m',
56
+ },
57
+ };
58
+
59
+ async function main(args) {
60
+ const client = await initClient(args);
61
+ const session = await client.openSession();
62
+
63
+ repl.start({
64
+ prompt: `${format.bold}dbsql > ${format.reset}`,
65
+ useColors: true,
66
+ eval: async (input, context, filename, callback) => {
67
+ try {
68
+ const result = await runQuery(session, input);
69
+ callback(null, result);
70
+ } catch (e) {
71
+ callback(null, e);
72
+ }
73
+ },
74
+ writer: (output) => {
75
+ if (output instanceof Error) {
76
+ const message = output?.response?.errorMessage || output.message;
77
+ return `${format.fg.red}Error: ${message}${format.reset}`;
78
+ } else {
79
+ if (!output?.length) {
80
+ return `${format.fg.cyan}Query executed successfully, but returned no results${format.reset}`;
81
+ }
82
+ logger.table(output)
83
+ return (ts.read() || '').toString();
84
+ }
85
+ },
86
+ }).on('exit', async () => {
87
+ await session.close();
88
+ await client.close();
89
+
90
+ process.exit();
91
+ });
92
+ }
93
+
94
+ program
95
+ .requiredOption('-h, --host <host>', 'Host (required)')
96
+ .requiredOption('-e, --endpoint <endpointId>', 'SQL endpoint ID (required)')
97
+ .requiredOption('-t, --token <token>', 'Personal access token (required)')
98
+ .showHelpAfterError();
99
+
100
+ program.parse(process.argv);
101
+
102
+ main({
103
+ host: program.opts().host,
104
+ endpointId: program.opts().endpoint,
105
+ token: program.opts().token,
106
+ });
@@ -0,0 +1,55 @@
1
+ const { DBSQLClient } = require('../');
2
+
3
+ const client = new DBSQLClient();
4
+
5
+ const utils = DBSQLClient.utils;
6
+
7
+
8
+ const [host, path, token] = process.argv.slice(2);
9
+
10
+ client.connect({ host, path, token }).then(async client => {
11
+ const session = await client.openSession();
12
+ await createTables(session);
13
+
14
+ const typeInfo = await session.getTypeInfo().then(handleOperation);
15
+ console.log(typeInfo);
16
+ console.log();
17
+
18
+ const catalogs = await session.getCatalogs().then(handleOperation);
19
+ console.log(catalogs);
20
+ console.log();
21
+
22
+ const schemas = await session.getSchemas({}).then(handleOperation);
23
+ console.log(schemas);
24
+ console.log();
25
+
26
+ const tables = await session.getTables({}).then(handleOperation);
27
+ console.log(tables);
28
+ console.log();
29
+
30
+ const tableTypes = await session.getTableTypes({}).then(handleOperation);
31
+ console.log(tableTypes);
32
+ console.log();
33
+
34
+ const columns = await session.getColumns({}).then(handleOperation);
35
+ console.log(columns);
36
+ console.log();
37
+
38
+ await session.close();
39
+ }).catch(error => {
40
+ console.log(error);
41
+ });
42
+
43
+ async function handleOperation(operation) {
44
+ await utils.waitUntilReady(operation, true, (stateResponse) => {
45
+ console.log(stateResponse.taskStatus);
46
+ });
47
+ await utils.fetchAll(operation);
48
+ await operation.close();
49
+ return utils.getResult(operation).getValue();
50
+ }
51
+
52
+ const createTables = async (session) => {
53
+ await session.executeStatement('create table if not exists table1 ( id string, value integer )').then(handleOperation);
54
+ await session.executeStatement('create table if not exists table2 ( id string, table1_fk integer )').then(handleOperation);
55
+ };
@@ -0,0 +1,18 @@
1
+ const { DBSQLClient, thrift } = require('../');
2
+
3
+ const client = new DBSQLClient();
4
+
5
+ const [host, path, token] = process.argv.slice(2);
6
+
7
+ client.connect({ host, path, token }).then(async client => {
8
+ const session = await client.openSession();
9
+ const response = await session.getInfo(
10
+ thrift.TCLIService_types.TGetInfoType.CLI_DBMS_VER
11
+ );
12
+
13
+ console.log(response.getValue());
14
+
15
+ await session.close();
16
+ }).catch(error => {
17
+ console.log(error);
18
+ });
package/nyc.config.js ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ exclude: [
5
+ "thrift/**",
6
+ "tests/**"
7
+ ]
8
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@databricks/sql",
3
+ "version": "0.1.8-beta.1",
4
+ "description": "Driver for connection to Databricks SQL via Thrift API.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "directories": {
8
+ "example": "examples",
9
+ "test": "tests"
10
+ },
11
+ "engines": {
12
+ "node": ">=14.0.0"
13
+ },
14
+ "scripts": {
15
+ "e2e": "mocha 'tests/e2e/**/*.test.js' --timeout=300000",
16
+ "test": "nyc --reporter=lcov mocha 'tests/unit/**/*.test.js'",
17
+ "coverage": "codecov",
18
+ "build": "tsc",
19
+ "watch": "tsc -w"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/databricks/databricks-sql-nodejs/"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/databricks/databricks-sql-nodejs/issues"
27
+ },
28
+ "homepage": "https://github.com/databricks/databricks-sql-nodejs#readme",
29
+ "keywords": [
30
+ "databricks sql",
31
+ "hiveserver2",
32
+ "apache",
33
+ "hive",
34
+ "hs2",
35
+ "client",
36
+ "thrift",
37
+ "nodejs",
38
+ "js",
39
+ "hive",
40
+ "hive js"
41
+ ],
42
+ "license": "Apache 2.0",
43
+ "devDependencies": {
44
+ "@types/node": "^18.0.0",
45
+ "chai": "^4.3.6",
46
+ "codecov": "^3.8.3",
47
+ "mocha": "^10.0.0",
48
+ "nyc": "^15.1.0",
49
+ "typescript": "^4.7.4"
50
+ },
51
+ "dependencies": {
52
+ "commander": "^9.3.0",
53
+ "node-int64": "^0.4.0",
54
+ "thrift": "^0.16.0"
55
+ }
56
+ }
@@ -0,0 +1,353 @@
1
+ const { expect } = require('chai');
2
+ const config = require('./utils/config');
3
+ const logger = require('./utils/logger')(config.logger);
4
+ const { DBSQLClient, thrift } = require('../..');
5
+
6
+ const utils = DBSQLClient.utils;
7
+
8
+ const openSession = async () => {
9
+ const client = new DBSQLClient();
10
+
11
+ const connection = await client.connect({
12
+ host: config.host,
13
+ path: config.path,
14
+ token: config.token,
15
+ });
16
+
17
+ const session = await connection.openSession({
18
+ client_protocol: thrift.TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
19
+ });
20
+
21
+ if (config.database.length === 2) {
22
+ await execute(session, `USE CATALOG ${config.database[0]}`);
23
+ await execute(session, `USE DATABASE ${config.database[1]}`);
24
+ }
25
+
26
+ return session;
27
+ };
28
+
29
+ const execute = async (session, statement) => {
30
+ const operation = await session.executeStatement(statement, { runAsync: true });
31
+
32
+ await utils.waitUntilReady(operation, true, (stateResponse) => {
33
+ logger(stateResponse.taskStatus);
34
+ });
35
+ await utils.fetchAll(operation);
36
+ await operation.close();
37
+ return utils.getResult(operation).getValue();
38
+ };
39
+
40
+ function removeTrailingMetadata(columns) {
41
+ const result = [];
42
+ for (let i = 0; i < columns.length; i++) {
43
+ const col = columns[i];
44
+ if (col.col_name === "") {
45
+ break;
46
+ }
47
+ result.push(col);
48
+ }
49
+ return result;
50
+ }
51
+
52
+ describe('Data types', () => {
53
+ it('primitive data types should presented correctly', async () => {
54
+ const session = await openSession();
55
+ try {
56
+ await execute(session, `DROP TABLE IF EXISTS primitiveTypes`);
57
+ await execute(session, `
58
+ CREATE TABLE IF NOT EXISTS primitiveTypes (
59
+ bool
60
+ boolean,
61
+ tiny_int
62
+ tinyint,
63
+ small_int
64
+ smallint,
65
+ int_type
66
+ int,
67
+ big_int
68
+ bigint,
69
+ flt
70
+ float,
71
+ dbl
72
+ double,
73
+ dec
74
+ decimal(3, 2),
75
+ str string,
76
+ ts timestamp,
77
+ bin binary,
78
+ chr char(10),
79
+ vchr varchar(10),
80
+ dat date
81
+ )
82
+ `);
83
+
84
+ const columns = await execute(session, 'describe primitiveTypes');
85
+ expect(removeTrailingMetadata(columns)).to.be.deep.eq([
86
+ {
87
+ "col_name": "bool",
88
+ "data_type": "boolean",
89
+ "comment": ""
90
+ },
91
+ {
92
+ "col_name": "tiny_int",
93
+ "data_type": "tinyint",
94
+ "comment": ""
95
+ },
96
+ {
97
+ "col_name": "small_int",
98
+ "data_type": "smallint",
99
+ "comment": ""
100
+ },
101
+ {
102
+ "col_name": "int_type",
103
+ "data_type": "int",
104
+ "comment": ""
105
+ },
106
+ {
107
+ "col_name": "big_int",
108
+ "data_type": "bigint",
109
+ "comment": ""
110
+ },
111
+ {
112
+ "col_name": "flt",
113
+ "data_type": "float",
114
+ "comment": ""
115
+ },
116
+ {
117
+ "col_name": "dbl",
118
+ "data_type": "double",
119
+ "comment": ""
120
+ },
121
+ {
122
+ "col_name": "dec",
123
+ "data_type": "decimal(3,2)",
124
+ "comment": ""
125
+ },
126
+ {
127
+ "col_name": "str",
128
+ "data_type": "string",
129
+ "comment": ""
130
+ },
131
+ {
132
+ "col_name": "ts",
133
+ "data_type": "timestamp",
134
+ "comment": ""
135
+ },
136
+ {
137
+ "col_name": "bin",
138
+ "data_type": "binary",
139
+ "comment": ""
140
+ },
141
+ {
142
+ "col_name": "chr",
143
+ "data_type": "char(10)",
144
+ "comment": ""
145
+ },
146
+ {
147
+ "col_name": "vchr",
148
+ "data_type": "varchar(10)",
149
+ "comment": ""
150
+ },
151
+ {
152
+ "col_name": "dat",
153
+ "data_type": "date",
154
+ "comment": ""
155
+ }
156
+ ]);
157
+
158
+ await execute(session, `
159
+ insert into primitiveTypes (
160
+ bool, tiny_int, small_int, int_type, big_int, flt, dbl,
161
+ dec, str, ts, bin, chr, vchr, dat
162
+ ) values (
163
+ true, 127, 32000, 4000000, 372036854775807, 1.2, 2.2, 3.2, 'data',
164
+ '2014-01-17 00:17:13', 'data', 'a', 'b', '2014-01-17'
165
+ )
166
+ `);
167
+
168
+ const records = await execute(session, 'select * from primitiveTypes');
169
+ expect(records).to.be.deep.eq([
170
+ {
171
+ "bool": true,
172
+ "tiny_int": 127,
173
+ "small_int": 32000,
174
+ "int_type": 4000000,
175
+ "big_int": 372036854775807,
176
+ "flt": 1.2,
177
+ "dbl": 2.2,
178
+ "dec": 3.2,
179
+ "str": "data",
180
+ "ts": "2014-01-17 00:17:13",
181
+ "bin": Buffer.from('data'),
182
+ "chr": "a",
183
+ "vchr": "b",
184
+ "dat": "2014-01-17"
185
+ }
186
+ ]);
187
+
188
+ await session.close();
189
+ } catch (error) {
190
+ logger(error);
191
+ await session.close()
192
+ throw error;
193
+ }
194
+ });
195
+
196
+ it('interval types should be presented correctly', async () => {
197
+ const session = await openSession();
198
+ try {
199
+ await execute(session, `DROP TABLE IF EXISTS intervalTypes`);
200
+ await execute(session, `
201
+ CREATE TABLE intervalTypes AS
202
+ SELECT INTERVAL '1' day AS day_interval, INTERVAL '1' month AS month_interval
203
+ `);
204
+
205
+ const columns = await execute(session, 'describe intervalTypes');
206
+ expect(removeTrailingMetadata(columns)).to.be.deep.eq([
207
+ {
208
+ "col_name": "day_interval",
209
+ "data_type": "interval day",
210
+ "comment": ""
211
+ },
212
+ {
213
+ "col_name": "month_interval",
214
+ "data_type": "interval month",
215
+ "comment": ""
216
+ }
217
+ ]);
218
+
219
+ const records = await execute(session, 'select * from intervalTypes');
220
+ expect(records).to.be.deep.eq([
221
+ {
222
+ day_interval: "1 00:00:00.000000000",
223
+ month_interval: "0-1"
224
+ }
225
+ ]);
226
+
227
+ await session.close();
228
+ } catch (error) {
229
+ logger(error);
230
+ await session.close();
231
+ throw error;
232
+ }
233
+ });
234
+
235
+ it('complex types should be presented correctly', async () => {
236
+ const session = await openSession();
237
+ try {
238
+ await execute(session, `DROP TABLE IF EXISTS dummy`);
239
+ await execute(session, `DROP TABLE IF EXISTS complexTypes`);
240
+ await execute(session, `create table dummy( id string )`);
241
+ await execute(session, `insert into dummy (id) values (1)`);
242
+ await execute(session, `
243
+ CREATE TABLE complexTypes (
244
+ id int,
245
+ arr_type array<string>,
246
+ map_type map<string, int>,
247
+ struct_type struct<city:string,state:string>
248
+ )
249
+ `);
250
+
251
+ const columns = await execute(session, 'describe complexTypes');
252
+ expect(removeTrailingMetadata(columns)).to.be.deep.eq([
253
+ {
254
+ "col_name": "id",
255
+ "data_type": "int",
256
+ "comment": ""
257
+ },
258
+ {
259
+ "col_name": "arr_type",
260
+ "data_type": "array<string>",
261
+ "comment": ""
262
+ },
263
+ {
264
+ "col_name": "map_type",
265
+ "data_type": "map<string,int>",
266
+ "comment": ""
267
+ },
268
+ {
269
+ "col_name": "struct_type",
270
+ "data_type": "struct<city:string,state:string>",
271
+ "comment": ""
272
+ }
273
+ ]);
274
+
275
+ await execute(session, `
276
+ INSERT INTO table complexTypes SELECT
277
+ POSITIVE(1) as id,
278
+ array('a', 'b') as arr_type,
279
+ map('key', 12) as map_type,
280
+ named_struct('city','Tampa','State','FL') as struct_type
281
+ FROM dummy
282
+ `);
283
+ await execute(session, `
284
+ INSERT INTO table complexTypes SELECT
285
+ POSITIVE(2) as id,
286
+ array('c', 'd') as arr_type,
287
+ map('key2', 12) as map_type,
288
+ named_struct('city','Albany','State','NY') as struct_type
289
+ FROM dummy
290
+ `);
291
+ await execute(session, `
292
+ INSERT INTO table complexTypes SELECT
293
+ POSITIVE(3) as id,
294
+ array('e', 'd') as arr_type,
295
+ map('key2', 13) as map_type,
296
+ named_struct('city','Los Angeles','State','CA') as struct_type
297
+ FROM dummy
298
+ `);
299
+
300
+ const records = await execute(session, 'select * from complexTypes order by id asc');
301
+ expect(records).to.be.deep.eq([
302
+ {
303
+ "id": 1,
304
+ "arr_type": [
305
+ "a",
306
+ "b"
307
+ ],
308
+ "map_type": {
309
+ "key": 12
310
+ },
311
+ "struct_type": {
312
+ "city": "Tampa",
313
+ "state": "FL"
314
+ }
315
+ },
316
+ {
317
+ "id": 2,
318
+ "arr_type": [
319
+ "c",
320
+ "d"
321
+ ],
322
+ "map_type": {
323
+ "key2": 12
324
+ },
325
+ "struct_type": {
326
+ "city": "Albany",
327
+ "state": "NY"
328
+ }
329
+ },
330
+ {
331
+ "id": 3,
332
+ "arr_type": [
333
+ "e",
334
+ "d"
335
+ ],
336
+ "map_type": {
337
+ "key2": 13
338
+ },
339
+ "struct_type": {
340
+ "city": "Los Angeles",
341
+ "state": "CA"
342
+ }
343
+ }
344
+ ]);
345
+
346
+ await session.close();
347
+ } catch(error) {
348
+ logger(error);
349
+ await session.close()
350
+ throw error;
351
+ }
352
+ });
353
+ });
@@ -0,0 +1,20 @@
1
+ let overrides = {};
2
+ try {
3
+ overrides = require('./config.local');
4
+ } catch (e) {
5
+ }
6
+
7
+ // Create file named `config.local.js` in the same directory and override config there
8
+ module.exports = {
9
+ // Where to log: CONSOLE, FILE, QUIET
10
+ logger: 'FILE',
11
+ // Host, like ****.cloud.databricks.com
12
+ host: undefined,
13
+ // API path: /sql/1.0/endpoints/****************
14
+ path: undefined,
15
+ // Access token: dapi********************************
16
+ token: undefined,
17
+ // Catalog and database to use for testing; specify both or leave array empty to use defaults
18
+ database: [],
19
+ ...overrides,
20
+ };
@@ -0,0 +1,22 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const getMessage = (message) => {
5
+ return (new Date()) + ' [INFO] ' + message + '\n';
6
+ };
7
+
8
+ const logToFile = (message) => {
9
+ fs.appendFileSync(path.join(__dirname, '../../e2e.log'), getMessage(message));
10
+ };
11
+
12
+ module.exports = (type = 'CONSOLE') => {
13
+ switch (type) {
14
+ case 'QUIET':
15
+ return () => {};
16
+ case 'FILE':
17
+ return logToFile;
18
+ case 'CONSOLE':
19
+ default:
20
+ return message => console.log(message);
21
+ }
22
+ };