@databricks/sql 0.1.8-beta.1 → 1.0.0

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 (253) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/NOTICE +35 -0
  3. package/README.md +41 -20
  4. package/dist/DBSQLClient.d.ts +34 -39
  5. package/dist/DBSQLClient.js +137 -98
  6. package/dist/DBSQLClient.js.map +1 -1
  7. package/dist/DBSQLLogger.d.ts +12 -0
  8. package/dist/DBSQLLogger.js +43 -0
  9. package/dist/DBSQLLogger.js.map +1 -0
  10. package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +13 -0
  11. package/dist/DBSQLOperation/CompleteOperationHelper.js +61 -0
  12. package/dist/DBSQLOperation/CompleteOperationHelper.js.map +1 -0
  13. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +14 -0
  14. package/dist/DBSQLOperation/FetchResultsHelper.js +79 -0
  15. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -0
  16. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +17 -0
  17. package/dist/DBSQLOperation/OperationStatusHelper.js +115 -0
  18. package/dist/DBSQLOperation/OperationStatusHelper.js.map +1 -0
  19. package/dist/DBSQLOperation/SchemaHelper.d.ts +10 -0
  20. package/dist/DBSQLOperation/SchemaHelper.js +39 -0
  21. package/dist/DBSQLOperation/SchemaHelper.js.map +1 -0
  22. package/dist/DBSQLOperation/getResult.d.ts +2 -0
  23. package/dist/DBSQLOperation/getResult.js +19 -0
  24. package/dist/DBSQLOperation/getResult.js.map +1 -0
  25. package/dist/DBSQLOperation/index.d.ts +55 -0
  26. package/dist/DBSQLOperation/index.js +139 -0
  27. package/dist/DBSQLOperation/index.js.map +1 -0
  28. package/dist/DBSQLSession.d.ts +99 -0
  29. package/dist/DBSQLSession.js +187 -0
  30. package/dist/DBSQLSession.js.map +1 -0
  31. package/dist/connection/auth/NoSaslAuthentication.d.ts +2 -2
  32. package/dist/connection/auth/NoSaslAuthentication.js +9 -9
  33. package/dist/connection/auth/NoSaslAuthentication.js.map +1 -1
  34. package/dist/connection/auth/PlainHttpAuthentication.d.ts +2 -2
  35. package/dist/connection/auth/PlainHttpAuthentication.js +9 -21
  36. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  37. package/dist/connection/auth/helpers/SaslPackageFactory.js +5 -9
  38. package/dist/connection/auth/helpers/SaslPackageFactory.js.map +1 -1
  39. package/dist/connection/connections/HttpConnection.d.ts +4 -4
  40. package/dist/connection/connections/HttpConnection.js +42 -47
  41. package/dist/connection/connections/HttpConnection.js.map +1 -1
  42. package/dist/connection/contracts/IAuthentication.d.ts +1 -1
  43. package/dist/connection/transports/HttpTransport.d.ts +1 -1
  44. package/dist/connection/transports/HttpTransport.js +16 -31
  45. package/dist/connection/transports/HttpTransport.js.map +1 -1
  46. package/dist/contracts/IDBSQLClient.d.ts +21 -0
  47. package/dist/contracts/{IHiveClient.js → IDBSQLClient.js} +1 -1
  48. package/dist/contracts/IDBSQLClient.js.map +1 -0
  49. package/dist/contracts/IDBSQLLogger.d.ts +13 -0
  50. package/dist/contracts/IDBSQLLogger.js +11 -0
  51. package/dist/contracts/IDBSQLLogger.js.map +1 -0
  52. package/dist/contracts/{IHiveSession.d.ts → IDBSQLSession.d.ts} +59 -45
  53. package/dist/contracts/{IHiveSession.js → IDBSQLSession.js} +1 -1
  54. package/dist/contracts/IDBSQLSession.js.map +1 -0
  55. package/dist/contracts/IOperation.d.ts +26 -23
  56. package/dist/dto/InfoValue.d.ts +5 -3
  57. package/dist/dto/InfoValue.js +11 -14
  58. package/dist/dto/InfoValue.js.map +1 -1
  59. package/dist/dto/Status.js +9 -10
  60. package/dist/dto/Status.js.map +1 -1
  61. package/dist/errors/AuthenticationError.d.ts +1 -1
  62. package/dist/errors/AuthenticationError.js +3 -23
  63. package/dist/errors/AuthenticationError.js.map +1 -1
  64. package/dist/errors/HiveDriverError.js +2 -22
  65. package/dist/errors/HiveDriverError.js.map +1 -1
  66. package/dist/errors/OperationStateError.d.ts +4 -4
  67. package/dist/errors/OperationStateError.js +6 -24
  68. package/dist/errors/OperationStateError.js.map +1 -1
  69. package/dist/errors/StatusError.d.ts +2 -2
  70. package/dist/errors/StatusError.js +3 -4
  71. package/dist/errors/StatusError.js.map +1 -1
  72. package/dist/factory/StatusFactory.d.ts +2 -4
  73. package/dist/factory/StatusFactory.js +16 -21
  74. package/dist/factory/StatusFactory.js.map +1 -1
  75. package/dist/hive/Commands/BaseCommand.d.ts +3 -4
  76. package/dist/hive/Commands/BaseCommand.js +10 -12
  77. package/dist/hive/Commands/BaseCommand.js.map +1 -1
  78. package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +3 -10
  79. package/dist/hive/Commands/CancelDelegationTokenCommand.js +7 -26
  80. package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -1
  81. package/dist/hive/Commands/CancelOperationCommand.d.ts +3 -9
  82. package/dist/hive/Commands/CancelOperationCommand.js +7 -26
  83. package/dist/hive/Commands/CancelOperationCommand.js.map +1 -1
  84. package/dist/hive/Commands/CloseOperationCommand.d.ts +3 -9
  85. package/dist/hive/Commands/CloseOperationCommand.js +7 -26
  86. package/dist/hive/Commands/CloseOperationCommand.js.map +1 -1
  87. package/dist/hive/Commands/CloseSessionCommand.d.ts +3 -9
  88. package/dist/hive/Commands/CloseSessionCommand.js +7 -26
  89. package/dist/hive/Commands/CloseSessionCommand.js.map +1 -1
  90. package/dist/hive/Commands/ExecuteStatementCommand.d.ts +3 -15
  91. package/dist/hive/Commands/ExecuteStatementCommand.js +7 -26
  92. package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -1
  93. package/dist/hive/Commands/FetchResultsCommand.d.ts +4 -16
  94. package/dist/hive/Commands/FetchResultsCommand.js +10 -26
  95. package/dist/hive/Commands/FetchResultsCommand.js.map +1 -1
  96. package/dist/hive/Commands/GetCatalogsCommand.d.ts +3 -10
  97. package/dist/hive/Commands/GetCatalogsCommand.js +7 -26
  98. package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -1
  99. package/dist/hive/Commands/GetColumnsCommand.d.ts +3 -14
  100. package/dist/hive/Commands/GetColumnsCommand.js +7 -26
  101. package/dist/hive/Commands/GetColumnsCommand.js.map +1 -1
  102. package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +3 -16
  103. package/dist/hive/Commands/GetCrossReferenceCommand.js +7 -26
  104. package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -1
  105. package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +3 -12
  106. package/dist/hive/Commands/GetDelegationTokenCommand.js +7 -26
  107. package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -1
  108. package/dist/hive/Commands/GetFunctionsCommand.d.ts +3 -13
  109. package/dist/hive/Commands/GetFunctionsCommand.js +7 -26
  110. package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -1
  111. package/dist/hive/Commands/GetInfoCommand.d.ts +3 -14
  112. package/dist/hive/Commands/GetInfoCommand.js +7 -26
  113. package/dist/hive/Commands/GetInfoCommand.js.map +1 -1
  114. package/dist/hive/Commands/GetOperationStatusCommand.d.ts +3 -21
  115. package/dist/hive/Commands/GetOperationStatusCommand.js +7 -26
  116. package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -1
  117. package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +3 -13
  118. package/dist/hive/Commands/GetPrimaryKeysCommand.js +7 -26
  119. package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -1
  120. package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +3 -10
  121. package/dist/hive/Commands/GetResultSetMetadataCommand.js +7 -26
  122. package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -1
  123. package/dist/hive/Commands/GetSchemasCommand.d.ts +3 -12
  124. package/dist/hive/Commands/GetSchemasCommand.js +7 -26
  125. package/dist/hive/Commands/GetSchemasCommand.js.map +1 -1
  126. package/dist/hive/Commands/GetTableTypesCommand.d.ts +3 -10
  127. package/dist/hive/Commands/GetTableTypesCommand.js +7 -26
  128. package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -1
  129. package/dist/hive/Commands/GetTablesCommand.d.ts +3 -14
  130. package/dist/hive/Commands/GetTablesCommand.js +7 -26
  131. package/dist/hive/Commands/GetTablesCommand.js.map +1 -1
  132. package/dist/hive/Commands/GetTypeInfoCommand.d.ts +3 -10
  133. package/dist/hive/Commands/GetTypeInfoCommand.js +7 -26
  134. package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -1
  135. package/dist/hive/Commands/OpenSessionCommand.d.ts +9 -28
  136. package/dist/hive/Commands/OpenSessionCommand.js +16 -26
  137. package/dist/hive/Commands/OpenSessionCommand.js.map +1 -1
  138. package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +3 -10
  139. package/dist/hive/Commands/RenewDelegationTokenCommand.js +7 -26
  140. package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -1
  141. package/dist/hive/HiveDriver.d.ts +24 -49
  142. package/dist/hive/HiveDriver.js +87 -99
  143. package/dist/hive/HiveDriver.js.map +1 -1
  144. package/dist/hive/Types/index.d.ts +7 -218
  145. package/dist/hive/Types/index.js +11 -2
  146. package/dist/hive/Types/index.js.map +1 -1
  147. package/dist/index.d.ts +16 -16
  148. package/dist/index.js +19 -51
  149. package/dist/index.js.map +1 -1
  150. package/dist/result/IOperationResult.d.ts +0 -2
  151. package/dist/result/JsonResult.d.ts +5 -8
  152. package/dist/result/JsonResult.js +81 -99
  153. package/dist/result/JsonResult.js.map +1 -1
  154. package/dist/result/NullResult.d.ts +1 -3
  155. package/dist/result/NullResult.js +4 -8
  156. package/dist/result/NullResult.js.map +1 -1
  157. package/dist/utils/buildUserAgentString.d.ts +1 -0
  158. package/dist/utils/buildUserAgentString.js +25 -0
  159. package/dist/utils/buildUserAgentString.js.map +1 -0
  160. package/dist/utils/definedOrError.d.ts +1 -0
  161. package/dist/utils/definedOrError.js +10 -0
  162. package/dist/utils/definedOrError.js.map +1 -0
  163. package/dist/utils/formatProgress.d.ts +9 -0
  164. package/dist/utils/formatProgress.js +24 -0
  165. package/dist/utils/formatProgress.js.map +1 -0
  166. package/dist/utils/index.d.ts +4 -0
  167. package/dist/utils/index.js +37 -0
  168. package/dist/utils/index.js.map +1 -0
  169. package/package.json +28 -7
  170. package/thrift/TCLIService.d.ts +196 -0
  171. package/thrift/{gen-nodejs/TCLIService.js → TCLIService.js} +1 -397
  172. package/thrift/TCLIService_types.d.ts +947 -0
  173. package/thrift/{gen-nodejs/TCLIService_types.js → TCLIService_types.js} +2830 -516
  174. package/.gitattributes +0 -32
  175. package/CONTRIBUTING.md +0 -55
  176. package/dist/HiveClient.d.ts +0 -35
  177. package/dist/HiveClient.js +0 -156
  178. package/dist/HiveClient.js.map +0 -1
  179. package/dist/HiveOperation.d.ts +0 -65
  180. package/dist/HiveOperation.js +0 -190
  181. package/dist/HiveOperation.js.map +0 -1
  182. package/dist/HiveSession.d.ts +0 -30
  183. package/dist/HiveSession.js +0 -197
  184. package/dist/HiveSession.js.map +0 -1
  185. package/dist/contracts/IHiveClient.d.ts +0 -10
  186. package/dist/contracts/IHiveClient.js.map +0 -1
  187. package/dist/contracts/IHiveSession.js.map +0 -1
  188. package/dist/hive/Commands/GetQueryIdCommand.d.ts +0 -11
  189. package/dist/hive/Commands/GetQueryIdCommand.js +0 -34
  190. package/dist/hive/Commands/GetQueryIdCommand.js.map +0 -1
  191. package/dist/hive/Commands/SetClientInfoCommand.d.ts +0 -12
  192. package/dist/hive/Commands/SetClientInfoCommand.js +0 -34
  193. package/dist/hive/Commands/SetClientInfoCommand.js.map +0 -1
  194. package/dist/utils/GetResult.d.ts +0 -16
  195. package/dist/utils/GetResult.js +0 -38
  196. package/dist/utils/GetResult.js.map +0 -1
  197. package/dist/utils/HiveUtils.d.ts +0 -11
  198. package/dist/utils/HiveUtils.js +0 -39
  199. package/dist/utils/HiveUtils.js.map +0 -1
  200. package/dist/utils/ProgressUpdateTransformer.d.ts +0 -8
  201. package/dist/utils/ProgressUpdateTransformer.js +0 -33
  202. package/dist/utils/ProgressUpdateTransformer.js.map +0 -1
  203. package/dist/utils/WaitUntilReady.d.ts +0 -16
  204. package/dist/utils/WaitUntilReady.js +0 -120
  205. package/dist/utils/WaitUntilReady.js.map +0 -1
  206. package/docs/readme.md +0 -227
  207. package/docs/troubleshooting.md +0 -84
  208. package/examples/data_types.js +0 -173
  209. package/examples/repl +0 -106
  210. package/examples/session.js +0 -55
  211. package/examples/usage.js +0 -18
  212. package/nyc.config.js +0 -8
  213. package/tests/e2e/data_types.test.js +0 -353
  214. package/tests/e2e/utils/config.js +0 -20
  215. package/tests/e2e/utils/logger.js +0 -22
  216. package/tests/unit/HiveClient.test.js +0 -153
  217. package/tests/unit/HiveOperation.test.js +0 -340
  218. package/tests/unit/HiveSession.test.js +0 -146
  219. package/tests/unit/connection/auth/PlainHttpAuthentication.test.js +0 -44
  220. package/tests/unit/connection/connections/HttpConnection.test.js +0 -141
  221. package/tests/unit/dto/InfoValue.test.js +0 -50
  222. package/tests/unit/factory/StatusFactory.test.js +0 -62
  223. package/tests/unit/hive/HiveDriver.test.js +0 -115
  224. package/tests/unit/hive/commands/CancelDelegationTokenCommand.test.js +0 -43
  225. package/tests/unit/hive/commands/CancelOperationCommand.test.js +0 -45
  226. package/tests/unit/hive/commands/CloseOperationCommand.test.js +0 -45
  227. package/tests/unit/hive/commands/CloseSessionCommand.test.js +0 -38
  228. package/tests/unit/hive/commands/ExecuteStatementCommand.test.js +0 -54
  229. package/tests/unit/hive/commands/FetchResultsCommand.test.js +0 -59
  230. package/tests/unit/hive/commands/GetCatalogsCommand.test.js +0 -50
  231. package/tests/unit/hive/commands/GetColumnsCommand.test.js +0 -50
  232. package/tests/unit/hive/commands/GetCrossReferenceCommand.test.js +0 -56
  233. package/tests/unit/hive/commands/GetDelegationTokenCommand.test.js +0 -45
  234. package/tests/unit/hive/commands/GetFunctionsCommand.test.js +0 -50
  235. package/tests/unit/hive/commands/GetInfoCommand.test.js +0 -51
  236. package/tests/unit/hive/commands/GetOperationStatusCommand.test.js +0 -63
  237. package/tests/unit/hive/commands/GetPrimaryKeysCommand.test.js +0 -50
  238. package/tests/unit/hive/commands/GetQueryIdCommand.test.js +0 -42
  239. package/tests/unit/hive/commands/GetResultSetMetadataCommand.test.js +0 -54
  240. package/tests/unit/hive/commands/GetSchemasCommand.test.js +0 -52
  241. package/tests/unit/hive/commands/GetTableTypesCommand.test.js +0 -50
  242. package/tests/unit/hive/commands/GetTablesCommand.test.js +0 -54
  243. package/tests/unit/hive/commands/GetTypeInfoCommand.test.js +0 -50
  244. package/tests/unit/hive/commands/OpenSessionCommand.test.js +0 -43
  245. package/tests/unit/hive/commands/RenewDelegationTokenCommand.test.js +0 -43
  246. package/tests/unit/hive/commands/SetClientInfoCommand.test.js +0 -45
  247. package/tests/unit/result/JsonResult.test.js +0 -295
  248. package/tests/unit/utils/GetResult.test.js +0 -30
  249. package/tests/unit/utils/HiveUtils.test.js +0 -60
  250. package/tests/unit/utils/ProgressUpdateTransformer.test.js +0 -28
  251. package/tests/unit/utils/WaitUntilReady.test.js +0 -105
  252. package/thrift/TCLIService.thrift +0 -1299
  253. package/tsconfig.json +0 -13
@@ -1,353 +0,0 @@
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
- });
@@ -1,20 +0,0 @@
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
- };
@@ -1,22 +0,0 @@
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
- };
@@ -1,153 +0,0 @@
1
- const { expect } = require('chai');
2
- const HiveClient = require('../../dist/HiveClient').default;
3
- const HiveSession = require('../../dist/HiveSession').default;
4
- const { TCLIService_types, TCLIService } = require('../../').thrift;
5
- const { auth: { NoSaslAuthentication }, connections: { HttpConnection } } = require('../../');
6
-
7
- const ConnectionProviderMock = (connection) => ({
8
- connect(options, auth) {
9
- this.options = options;
10
- this.auth = auth;
11
-
12
- return Promise.resolve({
13
- getConnection() {
14
- return connection || {
15
- on: () => {}
16
- };
17
- }
18
- });
19
- }
20
- });
21
-
22
- describe('HiveClient.connect', () => {
23
- it('should set nosal authenticatior by default', () => {
24
- const client = new HiveClient(TCLIService, TCLIService_types);
25
- const connectionProvider = ConnectionProviderMock();
26
-
27
- return client.connect({}, connectionProvider).catch(error => {
28
- expect(connectionProvider.auth).instanceOf(NoSaslAuthentication)
29
- });
30
- });
31
-
32
- it('should handle network errors', (cb) => {
33
- const client = new HiveClient(TCLIService, TCLIService_types);
34
- client.thrift = {
35
- createClient() {}
36
- };
37
- const connectionProvider = ConnectionProviderMock({
38
- on(name, handler) {
39
- handler(new Error('network error'));
40
- }
41
- });
42
-
43
- client.on('error', (error) => {
44
- expect(error.message).to.be.eq('network error');
45
- cb();
46
- });
47
-
48
- client.connect({}, connectionProvider).catch(error => {
49
- cb(error);
50
- });
51
- });
52
-
53
- it('should use client auth provider', () => {
54
- const client = new HiveClient(TCLIService, TCLIService_types);
55
- client.thrift = {
56
- createClient() {}
57
- };
58
- const connectionProvider = ConnectionProviderMock();
59
- const customAuthProvider = {};
60
-
61
- client.connect({}, connectionProvider, customAuthProvider).then(() => {
62
- expect(client.authProvider).to.be.eq(customAuthProvider);
63
- expect(connectionProvider.auth).to.be.eq(customAuthProvider);
64
- });
65
- });
66
-
67
- it('should use http connection by default', (cb) => {
68
- const client = new HiveClient(TCLIService, TCLIService_types);
69
- client.thrift = {
70
- createClient() {}
71
- };
72
-
73
- client.connect({path: '', port: 0})
74
- .then(() => {
75
- expect(client.connectionProvider).instanceOf(HttpConnection);
76
- cb();
77
- })
78
- .catch(cb);
79
- });
80
- });
81
-
82
- describe('HiveClient.openSession', () => {
83
- it('should successfully open session', () => {
84
- const client = new HiveClient(TCLIService, TCLIService_types);
85
- client.client = {
86
- OpenSession(req, cb) {
87
- cb(null, { status: {}, sessionHandle: {} });
88
- }
89
- };
90
- client.connection = {
91
- isConnected() {
92
- return true;
93
- }
94
- };
95
- return client.openSession({
96
- client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
97
- }).then((session) => {
98
- expect(session).instanceOf(HiveSession);
99
- });
100
- });
101
-
102
- it('should throw an exception when connection is lost', (done) => {
103
- const client = new HiveClient(TCLIService, TCLIService_types);
104
- client.connection = {
105
- isConnected() {
106
- return false;
107
- }
108
- };
109
-
110
- client.openSession({
111
- client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
112
- }).catch((error) => {
113
- expect(error.message).to.be.eq('HiveClient: connection is lost');
114
- done();
115
- });
116
- });
117
- });
118
-
119
- describe('HiveClient.getClient', () => {
120
- it('should throw error if client is not set', () => {
121
- const client = new HiveClient(TCLIService, TCLIService_types);
122
- expect(() => client.getClient()).to.throw('HiveClient: client is not initialized');
123
- });
124
- });
125
-
126
- describe('HiveClient.close', () => {
127
- it('should close connection if it was initiated', () => {
128
- const client = new HiveClient(TCLIService, TCLIService_types);
129
- let closed = false;
130
- client.connection = {
131
- getConnection: () => ({ end: () => {
132
- closed = true;
133
- }})
134
- };
135
- client.close();
136
- expect(closed).to.be.true;
137
- });
138
-
139
- it('should do nothing if connection does not exist', () => {
140
- const client = new HiveClient(TCLIService, TCLIService_types);
141
- client.close();
142
- expect(true).to.be.true;
143
- });
144
-
145
- it('should do nothing if connection exists but cannot be finished', () => {
146
- const client = new HiveClient(TCLIService, TCLIService_types);
147
- client.connection = {
148
- getConnection: () => ({})
149
- };
150
- client.close();
151
- expect(true).to.be.true;
152
- });
153
- });