@databricks/sql 0.1.8-beta.1 → 0.1.8-beta.2

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 (248) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/NOTICE +35 -0
  3. package/README.md +42 -19
  4. package/dist/DBSQLClient.d.ts +23 -39
  5. package/dist/DBSQLClient.js +110 -98
  6. package/dist/DBSQLClient.js.map +1 -1
  7. package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +13 -0
  8. package/dist/DBSQLOperation/CompleteOperationHelper.js +61 -0
  9. package/dist/DBSQLOperation/CompleteOperationHelper.js.map +1 -0
  10. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +14 -0
  11. package/dist/DBSQLOperation/FetchResultsHelper.js +79 -0
  12. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -0
  13. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +17 -0
  14. package/dist/DBSQLOperation/OperationStatusHelper.js +115 -0
  15. package/dist/DBSQLOperation/OperationStatusHelper.js.map +1 -0
  16. package/dist/DBSQLOperation/SchemaHelper.d.ts +10 -0
  17. package/dist/DBSQLOperation/SchemaHelper.js +39 -0
  18. package/dist/DBSQLOperation/SchemaHelper.js.map +1 -0
  19. package/dist/DBSQLOperation/getResult.d.ts +2 -0
  20. package/dist/DBSQLOperation/getResult.js +19 -0
  21. package/dist/DBSQLOperation/getResult.js.map +1 -0
  22. package/dist/DBSQLOperation/index.d.ts +34 -0
  23. package/dist/DBSQLOperation/index.js +100 -0
  24. package/dist/DBSQLOperation/index.js.map +1 -0
  25. package/dist/{HiveSession.d.ts → DBSQLSession.d.ts} +8 -9
  26. package/dist/DBSQLSession.js +185 -0
  27. package/dist/DBSQLSession.js.map +1 -0
  28. package/dist/connection/auth/NoSaslAuthentication.d.ts +2 -2
  29. package/dist/connection/auth/NoSaslAuthentication.js +9 -9
  30. package/dist/connection/auth/NoSaslAuthentication.js.map +1 -1
  31. package/dist/connection/auth/PlainHttpAuthentication.d.ts +2 -2
  32. package/dist/connection/auth/PlainHttpAuthentication.js +9 -21
  33. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  34. package/dist/connection/auth/helpers/SaslPackageFactory.js +5 -9
  35. package/dist/connection/auth/helpers/SaslPackageFactory.js.map +1 -1
  36. package/dist/connection/connections/HttpConnection.d.ts +4 -4
  37. package/dist/connection/connections/HttpConnection.js +39 -47
  38. package/dist/connection/connections/HttpConnection.js.map +1 -1
  39. package/dist/connection/contracts/IAuthentication.d.ts +1 -1
  40. package/dist/connection/transports/HttpTransport.d.ts +1 -1
  41. package/dist/connection/transports/HttpTransport.js +16 -31
  42. package/dist/connection/transports/HttpTransport.js.map +1 -1
  43. package/dist/contracts/IDBSQLClient.d.ts +14 -0
  44. package/dist/contracts/{IHiveClient.js → IDBSQLClient.js} +1 -1
  45. package/dist/contracts/IDBSQLClient.js.map +1 -0
  46. package/dist/contracts/{IHiveSession.d.ts → IDBSQLSession.d.ts} +9 -7
  47. package/dist/contracts/{IHiveSession.js → IDBSQLSession.js} +1 -1
  48. package/dist/contracts/IDBSQLSession.js.map +1 -0
  49. package/dist/contracts/IOperation.d.ts +21 -21
  50. package/dist/contracts/IOperation.js +4 -0
  51. package/dist/contracts/IOperation.js.map +1 -1
  52. package/dist/dto/InfoValue.d.ts +5 -3
  53. package/dist/dto/InfoValue.js +11 -14
  54. package/dist/dto/InfoValue.js.map +1 -1
  55. package/dist/dto/Status.js +9 -10
  56. package/dist/dto/Status.js.map +1 -1
  57. package/dist/errors/AuthenticationError.d.ts +1 -1
  58. package/dist/errors/AuthenticationError.js +3 -23
  59. package/dist/errors/AuthenticationError.js.map +1 -1
  60. package/dist/errors/HiveDriverError.js +2 -22
  61. package/dist/errors/HiveDriverError.js.map +1 -1
  62. package/dist/errors/OperationStateError.d.ts +4 -4
  63. package/dist/errors/OperationStateError.js +6 -24
  64. package/dist/errors/OperationStateError.js.map +1 -1
  65. package/dist/errors/StatusError.d.ts +2 -2
  66. package/dist/errors/StatusError.js +3 -4
  67. package/dist/errors/StatusError.js.map +1 -1
  68. package/dist/factory/StatusFactory.d.ts +2 -4
  69. package/dist/factory/StatusFactory.js +16 -21
  70. package/dist/factory/StatusFactory.js.map +1 -1
  71. package/dist/hive/Commands/BaseCommand.d.ts +3 -4
  72. package/dist/hive/Commands/BaseCommand.js +10 -12
  73. package/dist/hive/Commands/BaseCommand.js.map +1 -1
  74. package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +3 -10
  75. package/dist/hive/Commands/CancelDelegationTokenCommand.js +7 -26
  76. package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -1
  77. package/dist/hive/Commands/CancelOperationCommand.d.ts +3 -9
  78. package/dist/hive/Commands/CancelOperationCommand.js +7 -26
  79. package/dist/hive/Commands/CancelOperationCommand.js.map +1 -1
  80. package/dist/hive/Commands/CloseOperationCommand.d.ts +3 -9
  81. package/dist/hive/Commands/CloseOperationCommand.js +7 -26
  82. package/dist/hive/Commands/CloseOperationCommand.js.map +1 -1
  83. package/dist/hive/Commands/CloseSessionCommand.d.ts +3 -9
  84. package/dist/hive/Commands/CloseSessionCommand.js +7 -26
  85. package/dist/hive/Commands/CloseSessionCommand.js.map +1 -1
  86. package/dist/hive/Commands/ExecuteStatementCommand.d.ts +3 -15
  87. package/dist/hive/Commands/ExecuteStatementCommand.js +7 -26
  88. package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -1
  89. package/dist/hive/Commands/FetchResultsCommand.d.ts +4 -16
  90. package/dist/hive/Commands/FetchResultsCommand.js +10 -26
  91. package/dist/hive/Commands/FetchResultsCommand.js.map +1 -1
  92. package/dist/hive/Commands/GetCatalogsCommand.d.ts +3 -10
  93. package/dist/hive/Commands/GetCatalogsCommand.js +7 -26
  94. package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -1
  95. package/dist/hive/Commands/GetColumnsCommand.d.ts +3 -14
  96. package/dist/hive/Commands/GetColumnsCommand.js +7 -26
  97. package/dist/hive/Commands/GetColumnsCommand.js.map +1 -1
  98. package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +3 -16
  99. package/dist/hive/Commands/GetCrossReferenceCommand.js +7 -26
  100. package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -1
  101. package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +3 -12
  102. package/dist/hive/Commands/GetDelegationTokenCommand.js +7 -26
  103. package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -1
  104. package/dist/hive/Commands/GetFunctionsCommand.d.ts +3 -13
  105. package/dist/hive/Commands/GetFunctionsCommand.js +7 -26
  106. package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -1
  107. package/dist/hive/Commands/GetInfoCommand.d.ts +3 -14
  108. package/dist/hive/Commands/GetInfoCommand.js +7 -26
  109. package/dist/hive/Commands/GetInfoCommand.js.map +1 -1
  110. package/dist/hive/Commands/GetOperationStatusCommand.d.ts +3 -21
  111. package/dist/hive/Commands/GetOperationStatusCommand.js +7 -26
  112. package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -1
  113. package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +3 -13
  114. package/dist/hive/Commands/GetPrimaryKeysCommand.js +7 -26
  115. package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -1
  116. package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +3 -10
  117. package/dist/hive/Commands/GetResultSetMetadataCommand.js +7 -26
  118. package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -1
  119. package/dist/hive/Commands/GetSchemasCommand.d.ts +3 -12
  120. package/dist/hive/Commands/GetSchemasCommand.js +7 -26
  121. package/dist/hive/Commands/GetSchemasCommand.js.map +1 -1
  122. package/dist/hive/Commands/GetTableTypesCommand.d.ts +3 -10
  123. package/dist/hive/Commands/GetTableTypesCommand.js +7 -26
  124. package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -1
  125. package/dist/hive/Commands/GetTablesCommand.d.ts +3 -14
  126. package/dist/hive/Commands/GetTablesCommand.js +7 -26
  127. package/dist/hive/Commands/GetTablesCommand.js.map +1 -1
  128. package/dist/hive/Commands/GetTypeInfoCommand.d.ts +3 -10
  129. package/dist/hive/Commands/GetTypeInfoCommand.js +7 -26
  130. package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -1
  131. package/dist/hive/Commands/OpenSessionCommand.d.ts +9 -28
  132. package/dist/hive/Commands/OpenSessionCommand.js +16 -26
  133. package/dist/hive/Commands/OpenSessionCommand.js.map +1 -1
  134. package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +3 -10
  135. package/dist/hive/Commands/RenewDelegationTokenCommand.js +7 -26
  136. package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -1
  137. package/dist/hive/HiveDriver.d.ts +24 -49
  138. package/dist/hive/HiveDriver.js +87 -99
  139. package/dist/hive/HiveDriver.js.map +1 -1
  140. package/dist/hive/Types/index.d.ts +7 -218
  141. package/dist/hive/Types/index.js +11 -2
  142. package/dist/hive/Types/index.js.map +1 -1
  143. package/dist/index.d.ts +14 -16
  144. package/dist/index.js +15 -51
  145. package/dist/index.js.map +1 -1
  146. package/dist/result/IOperationResult.d.ts +0 -2
  147. package/dist/result/JsonResult.d.ts +5 -8
  148. package/dist/result/JsonResult.js +81 -99
  149. package/dist/result/JsonResult.js.map +1 -1
  150. package/dist/result/NullResult.d.ts +1 -3
  151. package/dist/result/NullResult.js +4 -8
  152. package/dist/result/NullResult.js.map +1 -1
  153. package/dist/utils/buildUserAgentString.d.ts +1 -0
  154. package/dist/utils/buildUserAgentString.js +25 -0
  155. package/dist/utils/buildUserAgentString.js.map +1 -0
  156. package/dist/utils/definedOrError.d.ts +1 -0
  157. package/dist/utils/definedOrError.js +10 -0
  158. package/dist/utils/definedOrError.js.map +1 -0
  159. package/dist/utils/formatProgress.d.ts +9 -0
  160. package/dist/utils/formatProgress.js +24 -0
  161. package/dist/utils/formatProgress.js.map +1 -0
  162. package/dist/utils/index.d.ts +4 -0
  163. package/dist/utils/index.js +37 -0
  164. package/dist/utils/index.js.map +1 -0
  165. package/package.json +24 -6
  166. package/thrift/TCLIService.d.ts +196 -0
  167. package/thrift/{gen-nodejs/TCLIService.js → TCLIService.js} +1 -397
  168. package/thrift/TCLIService_types.d.ts +947 -0
  169. package/thrift/{gen-nodejs/TCLIService_types.js → TCLIService_types.js} +2830 -516
  170. package/.gitattributes +0 -32
  171. package/CONTRIBUTING.md +0 -55
  172. package/dist/HiveClient.d.ts +0 -35
  173. package/dist/HiveClient.js +0 -156
  174. package/dist/HiveClient.js.map +0 -1
  175. package/dist/HiveOperation.d.ts +0 -65
  176. package/dist/HiveOperation.js +0 -190
  177. package/dist/HiveOperation.js.map +0 -1
  178. package/dist/HiveSession.js +0 -197
  179. package/dist/HiveSession.js.map +0 -1
  180. package/dist/contracts/IHiveClient.d.ts +0 -10
  181. package/dist/contracts/IHiveClient.js.map +0 -1
  182. package/dist/contracts/IHiveSession.js.map +0 -1
  183. package/dist/hive/Commands/GetQueryIdCommand.d.ts +0 -11
  184. package/dist/hive/Commands/GetQueryIdCommand.js +0 -34
  185. package/dist/hive/Commands/GetQueryIdCommand.js.map +0 -1
  186. package/dist/hive/Commands/SetClientInfoCommand.d.ts +0 -12
  187. package/dist/hive/Commands/SetClientInfoCommand.js +0 -34
  188. package/dist/hive/Commands/SetClientInfoCommand.js.map +0 -1
  189. package/dist/utils/GetResult.d.ts +0 -16
  190. package/dist/utils/GetResult.js +0 -38
  191. package/dist/utils/GetResult.js.map +0 -1
  192. package/dist/utils/HiveUtils.d.ts +0 -11
  193. package/dist/utils/HiveUtils.js +0 -39
  194. package/dist/utils/HiveUtils.js.map +0 -1
  195. package/dist/utils/ProgressUpdateTransformer.d.ts +0 -8
  196. package/dist/utils/ProgressUpdateTransformer.js +0 -33
  197. package/dist/utils/ProgressUpdateTransformer.js.map +0 -1
  198. package/dist/utils/WaitUntilReady.d.ts +0 -16
  199. package/dist/utils/WaitUntilReady.js +0 -120
  200. package/dist/utils/WaitUntilReady.js.map +0 -1
  201. package/docs/readme.md +0 -227
  202. package/docs/troubleshooting.md +0 -84
  203. package/examples/data_types.js +0 -173
  204. package/examples/repl +0 -106
  205. package/examples/session.js +0 -55
  206. package/examples/usage.js +0 -18
  207. package/nyc.config.js +0 -8
  208. package/tests/e2e/data_types.test.js +0 -353
  209. package/tests/e2e/utils/config.js +0 -20
  210. package/tests/e2e/utils/logger.js +0 -22
  211. package/tests/unit/HiveClient.test.js +0 -153
  212. package/tests/unit/HiveOperation.test.js +0 -340
  213. package/tests/unit/HiveSession.test.js +0 -146
  214. package/tests/unit/connection/auth/PlainHttpAuthentication.test.js +0 -44
  215. package/tests/unit/connection/connections/HttpConnection.test.js +0 -141
  216. package/tests/unit/dto/InfoValue.test.js +0 -50
  217. package/tests/unit/factory/StatusFactory.test.js +0 -62
  218. package/tests/unit/hive/HiveDriver.test.js +0 -115
  219. package/tests/unit/hive/commands/CancelDelegationTokenCommand.test.js +0 -43
  220. package/tests/unit/hive/commands/CancelOperationCommand.test.js +0 -45
  221. package/tests/unit/hive/commands/CloseOperationCommand.test.js +0 -45
  222. package/tests/unit/hive/commands/CloseSessionCommand.test.js +0 -38
  223. package/tests/unit/hive/commands/ExecuteStatementCommand.test.js +0 -54
  224. package/tests/unit/hive/commands/FetchResultsCommand.test.js +0 -59
  225. package/tests/unit/hive/commands/GetCatalogsCommand.test.js +0 -50
  226. package/tests/unit/hive/commands/GetColumnsCommand.test.js +0 -50
  227. package/tests/unit/hive/commands/GetCrossReferenceCommand.test.js +0 -56
  228. package/tests/unit/hive/commands/GetDelegationTokenCommand.test.js +0 -45
  229. package/tests/unit/hive/commands/GetFunctionsCommand.test.js +0 -50
  230. package/tests/unit/hive/commands/GetInfoCommand.test.js +0 -51
  231. package/tests/unit/hive/commands/GetOperationStatusCommand.test.js +0 -63
  232. package/tests/unit/hive/commands/GetPrimaryKeysCommand.test.js +0 -50
  233. package/tests/unit/hive/commands/GetQueryIdCommand.test.js +0 -42
  234. package/tests/unit/hive/commands/GetResultSetMetadataCommand.test.js +0 -54
  235. package/tests/unit/hive/commands/GetSchemasCommand.test.js +0 -52
  236. package/tests/unit/hive/commands/GetTableTypesCommand.test.js +0 -50
  237. package/tests/unit/hive/commands/GetTablesCommand.test.js +0 -54
  238. package/tests/unit/hive/commands/GetTypeInfoCommand.test.js +0 -50
  239. package/tests/unit/hive/commands/OpenSessionCommand.test.js +0 -43
  240. package/tests/unit/hive/commands/RenewDelegationTokenCommand.test.js +0 -43
  241. package/tests/unit/hive/commands/SetClientInfoCommand.test.js +0 -45
  242. package/tests/unit/result/JsonResult.test.js +0 -295
  243. package/tests/unit/utils/GetResult.test.js +0 -30
  244. package/tests/unit/utils/HiveUtils.test.js +0 -60
  245. package/tests/unit/utils/ProgressUpdateTransformer.test.js +0 -28
  246. package/tests/unit/utils/WaitUntilReady.test.js +0 -105
  247. package/thrift/TCLIService.thrift +0 -1299
  248. package/tsconfig.json +0 -13
package/docs/readme.md DELETED
@@ -1,227 +0,0 @@
1
- # Getting started
2
-
3
- ## Table of Contents
4
-
5
- 1. [Foreword](#foreword)
6
- 2. [Example](#example) \
7
- 2.1. [Error handling](#error-handling) \
8
- 2.2. [TCLIService and TCLIService_types](#tcliservice-and-tcliservice_types)
9
- 3. [HiveSession](#hivesession)
10
- 4. [HiveOperation](#hiveoperation) \
11
- 4.1. [HiveUtils](#hiveutils)
12
- 5. [Status](#status)
13
- 6. [Finalize](#finalize)
14
-
15
- ## Foreword
16
-
17
- The library is written using TypeScript, so the best way to get to know how it works is to look through the code [lib/](/lib/), [tests/e2e](/tests/e2e/) and [examples](/examples).
18
-
19
- If you find any mistakes, misleading or some confusion feel free to create an issue or send a pull request.
20
-
21
- ## Example
22
-
23
- ```javascript
24
- const { DBSQLClient } = require('@databricks/sql');
25
-
26
- const client = new DBSQLClient();
27
- const utils = DBSQLClient.utils;
28
-
29
- client.connect({
30
- host: '...',
31
- path: '/sql/1.0/endpoints/****************',
32
- token: 'dapi********************************',
33
- }).then(async client => {
34
- const session = await client.openSession();
35
-
36
- const createTableOperation = await session.executeStatement(
37
- 'CREATE TABLE IF NOT EXISTS pokes (foo INT, bar STRING)'
38
- );
39
- await utils.waitUntilReady(createTableOperation, false, () => {});
40
- await createTableOperation.close();
41
-
42
- const loadDataOperation = await session.executeStatement(
43
- 'INSERT INTO pokes VALUES(123, "Hello, world!"'
44
- );
45
- await utils.waitUntilReady(loadDataOperation, false, () => {});
46
- await loadDataOperation.close();
47
-
48
- const selectDataOperation = await session.executeStatement(
49
- 'SELECT * FROM pokes', { runAsync: true }
50
- );
51
- await utils.waitUntilReady(selectDataOperation, false, () => {});
52
- await utils.fetchAll(selectDataOperation);
53
- await selectDataOperation.close();
54
-
55
- const result = utils.getResult(selectDataOperation).getValue();
56
-
57
- console.log(JSON.stringify(result, null, '\t'));
58
-
59
- await session.close();
60
- await client.close();
61
- })
62
- .catch(error => {
63
- console.error(error);
64
- });
65
- ```
66
-
67
- ### Error handling
68
-
69
- You may guess that some errors related to the network are thrown asynchronously and the driver does not maintain these cases, you should handle it on your own. The simplest way is to subscribe on "error" event:
70
-
71
- ```javascript
72
- client.on('error', (error) => {
73
- // ...
74
- });
75
- ```
76
-
77
- ### TCLIService and TCLIService_types
78
-
79
- TCLIService and TCLIService_types are generated from [TCLIService.thrift](https://github.com/apache/hive/blob/master/service-rpc/if/TCLIService.thrift).
80
-
81
- You can use the ones are provided by the driver or you can compile it on your own and provide via constructor to DBSQLClient ([details](https://thrift.apache.org/tutorial/)).
82
-
83
- ```
84
- thrift -r --gen js TCLIService.thrift
85
- ```
86
-
87
- TCLIService_types contains a number of constants that API uses, you do not have to know all of them, but sometimes it is useful to refer to [TCLIService.thrift](/thrift/TCLIService.thrift). Also, you may notice that most of the internal structures repeat the structures from [TCLIService.thrift](/thrift/TCLIService.thrift).
88
-
89
- ## HiveSession
90
-
91
- After you connect to the server you should open session to start working with Hive server.
92
-
93
- ```javascript
94
- ...
95
- const session = await client.openSession();
96
- ```
97
-
98
- To open session you must provide [OpenSessionRequest](/lib/hive/Commands/OpenSessionCommand.ts#L20) - the only required parameter is "client_protocol", which synchronizes the version of HiveServer2 API.
99
-
100
- Into "configuration" you may set any of the configurations that required for the session of your Hive instance.
101
-
102
- After the session is opened you will have the [HiveSession](/lib/HiveSession.ts) instance.
103
-
104
- Class [HiveSession](/lib/HiveSession.ts) is a facade for API that works with [SessionHandle](/lib/hive/Types/index.ts#L77).
105
-
106
- The method you will use the most is `executeStatement`
107
-
108
- ```javascript
109
- ...
110
- const operation = await session.executeStatement(
111
- 'CREATE TABLE IF NOT EXISTS pokes (foo INT, bar STRING)',
112
- { runSync: true }
113
- );
114
- ```
115
-
116
- - "statement" is DDL/DML statement (CREATE TABLE, INSERT, UPDATE, SELECT, LOAD, etc.)
117
-
118
- - [options](/lib/contracts/IHiveSession.ts#L14)
119
-
120
- - runAsync allows executing operation asynchronously.
121
-
122
- - confOverlay overrides session configuration properties.
123
-
124
- - timeout is the maximum time to execute an operation. It has Buffer type because timestamp in Hive has capacity 64. So for such value, you should use [node-int64](https://www.npmjs.com/package/node-int64) npm module.
125
-
126
- To know other methods see [IHiveSession](/lib/contracts/IHiveSession.ts) and [examples/session.js](/examples/session.js).
127
-
128
- ## HiveOperation
129
-
130
- In most cases, HiveSession methods return [HiveOperation](/lib/HiveOperation.ts), which helps you to retrieve requested data.
131
-
132
- After you fetch the result, the operation will have [TableSchema](/lib/hive/Types/index.ts#L143) and data (Array<[RowSet](/lib/hive/Types/index.ts#L218)>).
133
-
134
- ### HiveUtils
135
-
136
- Operation is executed asynchrnously, so before retrieving the result, you have to wait until it has finished state.
137
-
138
- ```javascript
139
- ...
140
- const response = await operation.status();
141
- const isReady = response.operationState === TCLIService_types.TOperationState.FINISHED_STATE;
142
- ```
143
-
144
- Also, the result is fetched by portitions, the size of a portion you can set by method [setMaxRows()](/lib/HiveOperation.ts#L115).
145
-
146
- ```javascript
147
- ...
148
- operation.setMaxRows(500);
149
- const status = await operation.fetch();
150
- ```
151
-
152
- After you fetch all data and you have schema and set of data, you can transfrom data in readable format.
153
-
154
- ```javascript
155
- ...
156
- const schema = operation.getSchema();
157
- const data = operation.getData();
158
- ```
159
-
160
- To simplify this process, you may use [HiveUtils](/lib/utils/HiveUtils.ts).
161
-
162
- ```typescript
163
- /**
164
- * Executes until operation has status finished or has one of the invalid states
165
- *
166
- * @param operation
167
- * @param progress flag for operation status command. If it sets true, response will include progressUpdateResponse with progress information
168
- * @param callback if callback specified it will be called each time the operation status response received and it will be passed as first parameter
169
- */
170
- waitUntilReady(
171
- operation: IOperation,
172
- progress?: boolean,
173
- callback?: Function
174
- ): Promise<IOperation>
175
-
176
- /**
177
- * Fetch data until operation hasMoreRows
178
- *
179
- * @param operation
180
- */
181
- fetchAll(operation: IOperation): Promise<IOperation>
182
-
183
- /**
184
- * Transforms operation result
185
- *
186
- * @param operation
187
- * @param resultHandler - you may specify your own handler. If not specified the result is transformed to JSON
188
- */
189
- getResult(
190
- operation: IOperation,
191
- resultHandler?: IOperationResult
192
- ): IOperationResult
193
- ```
194
-
195
- *NOTICE*
196
-
197
- - [node-int64](https://www.npmjs.com/package/node-int64) is used for types with capacity 64
198
-
199
- - to know how data is presented in JSON you may look at [JsonResult.test.js](/tests/unit/result/JsonResult.test.js)
200
-
201
- For more details see [IOperation](/lib/contracts/IOperation.ts).
202
-
203
- ### Example
204
-
205
- ```javascript
206
- const { DBSQLClient } = require('@databricks/sql');
207
- const utils = DBSQLClient.utils;
208
- ...
209
- await utils.waitUntilReady(
210
- operation,
211
- true,
212
- (stateResponse) => {
213
- console.log(stateResponse.taskStatus);
214
- }
215
- );
216
- await utils.fetchAll(operation);
217
-
218
- const result = utils.getResult(operation).getValue();
219
- ```
220
-
221
- ## Status
222
-
223
- You may notice, that most of the operations return [Status](/lib/dto/Status.ts) that helps you to determine the state of an operation. Also, status contains the error.
224
-
225
- ## Finalize
226
-
227
- After you finish working with the operation, session or client it is better to close it, each of them has a respective method (`close()`).
@@ -1,84 +0,0 @@
1
- # Troubleshooting
2
-
3
- This section contains recipies for common errors.
4
-
5
- - [413 FULL head](#413-full-head)
6
-
7
- ## 413 FULL head
8
-
9
- Related to issue [HIVE-11720](https://issues.apache.org/jira/browse/HIVE-11720)
10
-
11
- Workaround:
12
-
13
- increase the properties
14
-
15
- hive-site.xml
16
- ```xml
17
- <property>
18
- <name>hive.server2.thrift.http.response.header.size</name>
19
- <value>32768</value>
20
- </property>
21
- <property>
22
- <name>hive.server2.thrift.http.request.header.size</name>
23
- <value>32768</value>
24
- </property>
25
- ```
26
-
27
- ## Lost connection
28
-
29
- In this case DBSQLClient you have to reconnect.
30
-
31
- To define if the connection lost, you should subscribe on event "close":
32
-
33
- ```javascript
34
- client.on('close', () => {
35
- // do reconnect
36
- });
37
- ```
38
-
39
- Here is an example how you can manage reconnection:
40
-
41
- ```javascript
42
- const { DBSQLClient } = require('@databricks/sql');
43
-
44
- const RECONNECT_ATTEMPTS = 50;
45
- const RECONNECT_TIMEOUT = 3000; // millisecond
46
-
47
- const client = new DBSQLClient();
48
-
49
- client.on('close', () => {
50
- console.error('[Connection Lost]');
51
-
52
- connect(RECONNECT_ATTEMPTS).catch(error => {
53
- console.error('[Connection Failed]', error);
54
- });
55
- });
56
-
57
- connect(RECONNECT_ATTEMPTS).then(async client => {
58
- // work with client
59
- }, (error) => {
60
- console.error('[Connection Failed]', error);
61
- });
62
-
63
- const connect = (attempts) => new Promise((resolve, reject) => {
64
- setTimeout(() => {
65
- client.connect(...).then((client) => {
66
- console.log('Connected successfully!');
67
-
68
- resolve(client);
69
- }, (error) => {
70
- console.error('[Connection Failed] attempt:' + attempts, error.message);
71
-
72
- if (!attempts) {
73
- reject(error);
74
- } else {
75
- connect(attempts - 1).then(resolve, reject);
76
- }
77
- });
78
- }, RECONNECT_TIMEOUT);
79
- });
80
- ```
81
-
82
- Please, notice, that you do not have to re-create client and pass it to your services,
83
- after re-connection the old client instance works just fine,
84
- and you should be able to open session and work as you did before.
@@ -1,173 +0,0 @@
1
- const { DBSQLClient } = require('../');
2
-
3
- const client = new DBSQLClient();
4
-
5
- const utils = DBSQLClient.utils;
6
-
7
- const [host, path, token] = process.argv.slice(2);
8
-
9
- client.connect({ host, path, token }).then(async client => {
10
- try {
11
- client.on('error', (error) => {
12
- console.error(error);
13
- });
14
-
15
- const session = await client.openSession();
16
-
17
- await testPrimitiveTypes(session);
18
- await testComplexTypes(session);
19
- await testIntervals(session);
20
-
21
- const status = await session.close();
22
- console.log(status.success());
23
- await client.close();
24
- } catch (error) {
25
- console.error(error);
26
- await client.close();
27
- }
28
- });
29
-
30
- const testPrimitiveTypes = async (session) => {
31
- try {
32
- console.log('[info] create primitiveTypes');
33
- await execute(session, `
34
- CREATE TABLE IF NOT EXISTS primitiveTypes (
35
- bool boolean,
36
- tiny_int tinyint,
37
- small_int smallint,
38
- int_type int,
39
- big_int bigint,
40
- flt float,
41
- dbl double,
42
- dec decimal(3,2),
43
- str string,
44
- ts timestamp,
45
- bin binary,
46
- chr char(10),
47
- vchr varchar(10),
48
- dat date
49
- )`
50
- );
51
- console.log('[info] insert into primitiveTypes');
52
- await execute(session, `insert into primitiveTypes (
53
- bool,
54
- tiny_int,
55
- small_int,
56
- int_type,
57
- big_int,
58
- flt,
59
- dbl,
60
- dec,
61
- str,
62
- ts,
63
- bin,
64
- chr,
65
- vchr,
66
- dat
67
- ) values (
68
- true,
69
- 127,
70
- 32000,
71
- 4000000,
72
- 372036854775807,
73
- 1.2,
74
- 2.2,
75
- 3.2,
76
- 'data',
77
- '2014-01-17 00:17:13',
78
- 'data',
79
- 'a',
80
- 'b',
81
- '2014-01-17'
82
- )`);
83
- console.log('[info] fetch primitiveTypes');
84
- const result = await execute(session, 'select * from primitiveTypes');
85
-
86
- console.log(result);
87
- } finally {
88
- await execute(session, 'drop table primitiveTypes');
89
- }
90
- };
91
-
92
- const testIntervals = async (session) => {
93
- try {
94
- console.log('[info] create intervalTypes');
95
- await execute(session, `
96
- CREATE TABLE IF NOT EXISTS intervalTypes AS
97
- SELECT INTERVAL '1' day AS day_interval,
98
- INTERVAL '1' month AS month_interval
99
- `);
100
- console.log('[info] describe intervalTypes');
101
- console.log(await execute(session, `desc intervalTypes`));
102
- console.log('[info] fetch intervalTypes');
103
- console.log(await execute(session, 'select * from intervalTypes'));
104
- } finally {
105
- await execute(session, 'drop table intervalTypes');
106
- }
107
- };
108
-
109
- const testComplexTypes = async (session) => {
110
- try {
111
- console.log('[info] create dummy');
112
- await execute(session, `drop table if exists dummy`)
113
- await execute(session, `create table dummy( id string )`)
114
- console.log('[info] insert dummy value');
115
- await execute(session, `insert into dummy (id) values (1)`);
116
- console.log('[info] create complexTypes');
117
- await execute(session, `
118
- CREATE TABLE complexTypes (
119
- arr_type array<string>,
120
- map_type map<string, int>,
121
- struct_type struct<city:string,State:string>
122
- )
123
- `);
124
- console.log('[info] 1. insert complexTypes');
125
- await execute(session, `
126
- INSERT INTO table complexTypes SELECT
127
- array('a', 'b') as arr_type,
128
- map('key', 12) as map_type,
129
- named_struct('city','Tampa','State','FL') as struct_type
130
- FROM dummy
131
- `);
132
- console.log('[info] 2. insert complexTypes');
133
- await execute(session, `
134
- INSERT INTO table complexTypes SELECT
135
- array('c', 'd') as arr_type,
136
- map('key2', 12) as map_type,
137
- named_struct('city','Albany','State','NY') as struct_type
138
- FROM dummy
139
- `);
140
- console.log('[info] 3. insert complexTypes');
141
- await execute(session, `
142
- INSERT INTO table complexTypes SELECT
143
- array('e', 'd') as arr_type,
144
- map('key2', 13) as map_type,
145
- named_struct('city','Los Angeles','State','CA') as struct_type
146
- FROM dummy
147
- `);
148
- console.log('[info] fetch complexTypes');
149
- console.log(await execute(session, 'select * from complexTypes'));
150
- } finally {
151
- await Promise.all([
152
- execute(session, 'drop table dummy'),
153
- execute(session, 'drop table complexTypes')
154
- ]);
155
- }
156
- };
157
-
158
- const execute = async (session, statement) => {
159
- const operation = await session.executeStatement(statement, { runAsync: true });
160
-
161
- await utils.waitUntilReady(operation, true, (stateResponse) => {
162
- return;
163
- if (stateResponse.taskStatus) {
164
- console.log(stateResponse.taskStatus);
165
- } else {
166
- console.log(utils.formatProgress(stateResponse.progressUpdateResponse));
167
- }
168
- });
169
- await utils.fetchAll(operation);
170
- await operation.close();
171
-
172
- return utils.getResult(operation).getValue();
173
- };
package/examples/repl DELETED
@@ -1,106 +0,0 @@
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
- });
@@ -1,55 +0,0 @@
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
- };
package/examples/usage.js DELETED
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- exclude: [
5
- "thrift/**",
6
- "tests/**"
7
- ]
8
- };