@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.
- package/.gitattributes +32 -0
- package/CHANGELOG.md +1 -0
- package/CONTRIBUTING.md +55 -0
- package/LICENSE +201 -0
- package/README.md +78 -0
- package/dist/DBSQLClient.d.ts +42 -0
- package/dist/DBSQLClient.js +111 -0
- package/dist/DBSQLClient.js.map +1 -0
- package/dist/HiveClient.d.ts +35 -0
- package/dist/HiveClient.js +156 -0
- package/dist/HiveClient.js.map +1 -0
- package/dist/HiveOperation.d.ts +65 -0
- package/dist/HiveOperation.js +190 -0
- package/dist/HiveOperation.js.map +1 -0
- package/dist/HiveSession.d.ts +30 -0
- package/dist/HiveSession.js +197 -0
- package/dist/HiveSession.js.map +1 -0
- package/dist/connection/auth/NoSaslAuthentication.d.ts +5 -0
- package/dist/connection/auth/NoSaslAuthentication.js +15 -0
- package/dist/connection/auth/NoSaslAuthentication.js.map +1 -0
- package/dist/connection/auth/PlainHttpAuthentication.d.ts +15 -0
- package/dist/connection/auth/PlainHttpAuthentication.js +30 -0
- package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -0
- package/dist/connection/auth/helpers/SaslPackageFactory.d.ts +11 -0
- package/dist/connection/auth/helpers/SaslPackageFactory.js +24 -0
- package/dist/connection/auth/helpers/SaslPackageFactory.js.map +1 -0
- package/dist/connection/connections/HttpConnection.d.ts +13 -0
- package/dist/connection/connections/HttpConnection.js +77 -0
- package/dist/connection/connections/HttpConnection.js.map +1 -0
- package/dist/connection/contracts/IAuthentication.d.ts +4 -0
- package/dist/connection/contracts/IAuthentication.js +3 -0
- package/dist/connection/contracts/IAuthentication.js.map +1 -0
- package/dist/connection/contracts/IConnectionOptions.d.ts +23 -0
- package/dist/connection/contracts/IConnectionOptions.js +3 -0
- package/dist/connection/contracts/IConnectionOptions.js.map +1 -0
- package/dist/connection/contracts/IConnectionProvider.d.ts +6 -0
- package/dist/connection/contracts/IConnectionProvider.js +3 -0
- package/dist/connection/contracts/IConnectionProvider.js.map +1 -0
- package/dist/connection/contracts/IThriftConnection.d.ts +4 -0
- package/dist/connection/contracts/IThriftConnection.js +3 -0
- package/dist/connection/contracts/IThriftConnection.js.map +1 -0
- package/dist/connection/contracts/ITransport.d.ts +13 -0
- package/dist/connection/contracts/ITransport.js +3 -0
- package/dist/connection/contracts/ITransport.js.map +1 -0
- package/dist/connection/transports/HttpTransport.d.ts +14 -0
- package/dist/connection/transports/HttpTransport.js +39 -0
- package/dist/connection/transports/HttpTransport.js.map +1 -0
- package/dist/connection/types/AuthOptions.d.ts +4 -0
- package/dist/connection/types/AuthOptions.js +3 -0
- package/dist/connection/types/AuthOptions.js.map +1 -0
- package/dist/contracts/IHiveClient.d.ts +10 -0
- package/dist/contracts/IHiveClient.js +3 -0
- package/dist/contracts/IHiveClient.js.map +1 -0
- package/dist/contracts/IHiveSession.d.ts +126 -0
- package/dist/contracts/IHiveSession.js +3 -0
- package/dist/contracts/IHiveSession.js.map +1 -0
- package/dist/contracts/IOperation.d.ts +47 -0
- package/dist/contracts/IOperation.js +3 -0
- package/dist/contracts/IOperation.js.map +1 -0
- package/dist/dto/InfoValue.d.ts +9 -0
- package/dist/dto/InfoValue.js +31 -0
- package/dist/dto/InfoValue.js.map +1 -0
- package/dist/dto/Status.d.ts +15 -0
- package/dist/dto/Status.js +21 -0
- package/dist/dto/Status.js.map +1 -0
- package/dist/errors/AuthenticationError.d.ts +3 -0
- package/dist/errors/AuthenticationError.js +30 -0
- package/dist/errors/AuthenticationError.js.map +1 -0
- package/dist/errors/HiveDriverError.d.ts +2 -0
- package/dist/errors/HiveDriverError.js +26 -0
- package/dist/errors/HiveDriverError.js.map +1 -0
- package/dist/errors/OperationStateError.d.ts +6 -0
- package/dist/errors/OperationStateError.js +32 -0
- package/dist/errors/OperationStateError.js.map +1 -0
- package/dist/errors/StatusError.d.ts +8 -0
- package/dist/errors/StatusError.js +15 -0
- package/dist/errors/StatusError.js.map +1 -0
- package/dist/factory/StatusFactory.d.ts +14 -0
- package/dist/factory/StatusFactory.js +40 -0
- package/dist/factory/StatusFactory.js.map +1 -0
- package/dist/hive/Commands/BaseCommand.d.ts +7 -0
- package/dist/hive/Commands/BaseCommand.js +36 -0
- package/dist/hive/Commands/BaseCommand.js.map +1 -0
- package/dist/hive/Commands/CancelDelegationTokenCommand.d.ts +12 -0
- package/dist/hive/Commands/CancelDelegationTokenCommand.js +34 -0
- package/dist/hive/Commands/CancelDelegationTokenCommand.js.map +1 -0
- package/dist/hive/Commands/CancelOperationCommand.d.ts +11 -0
- package/dist/hive/Commands/CancelOperationCommand.js +34 -0
- package/dist/hive/Commands/CancelOperationCommand.js.map +1 -0
- package/dist/hive/Commands/CloseOperationCommand.d.ts +11 -0
- package/dist/hive/Commands/CloseOperationCommand.js +34 -0
- package/dist/hive/Commands/CloseOperationCommand.js.map +1 -0
- package/dist/hive/Commands/CloseSessionCommand.d.ts +11 -0
- package/dist/hive/Commands/CloseSessionCommand.js +34 -0
- package/dist/hive/Commands/CloseSessionCommand.js.map +1 -0
- package/dist/hive/Commands/ExecuteStatementCommand.d.ts +17 -0
- package/dist/hive/Commands/ExecuteStatementCommand.js +34 -0
- package/dist/hive/Commands/ExecuteStatementCommand.js.map +1 -0
- package/dist/hive/Commands/FetchResultsCommand.d.ts +20 -0
- package/dist/hive/Commands/FetchResultsCommand.js +34 -0
- package/dist/hive/Commands/FetchResultsCommand.js.map +1 -0
- package/dist/hive/Commands/GetCatalogsCommand.d.ts +12 -0
- package/dist/hive/Commands/GetCatalogsCommand.js +34 -0
- package/dist/hive/Commands/GetCatalogsCommand.js.map +1 -0
- package/dist/hive/Commands/GetColumnsCommand.d.ts +16 -0
- package/dist/hive/Commands/GetColumnsCommand.js +34 -0
- package/dist/hive/Commands/GetColumnsCommand.js.map +1 -0
- package/dist/hive/Commands/GetCrossReferenceCommand.d.ts +18 -0
- package/dist/hive/Commands/GetCrossReferenceCommand.js +34 -0
- package/dist/hive/Commands/GetCrossReferenceCommand.js.map +1 -0
- package/dist/hive/Commands/GetDelegationTokenCommand.d.ts +14 -0
- package/dist/hive/Commands/GetDelegationTokenCommand.js +34 -0
- package/dist/hive/Commands/GetDelegationTokenCommand.js.map +1 -0
- package/dist/hive/Commands/GetFunctionsCommand.d.ts +15 -0
- package/dist/hive/Commands/GetFunctionsCommand.js +34 -0
- package/dist/hive/Commands/GetFunctionsCommand.js.map +1 -0
- package/dist/hive/Commands/GetInfoCommand.d.ts +16 -0
- package/dist/hive/Commands/GetInfoCommand.js +34 -0
- package/dist/hive/Commands/GetInfoCommand.js.map +1 -0
- package/dist/hive/Commands/GetOperationStatusCommand.d.ts +23 -0
- package/dist/hive/Commands/GetOperationStatusCommand.js +34 -0
- package/dist/hive/Commands/GetOperationStatusCommand.js.map +1 -0
- package/dist/hive/Commands/GetPrimaryKeysCommand.d.ts +15 -0
- package/dist/hive/Commands/GetPrimaryKeysCommand.js +34 -0
- package/dist/hive/Commands/GetPrimaryKeysCommand.js.map +1 -0
- package/dist/hive/Commands/GetQueryIdCommand.d.ts +11 -0
- package/dist/hive/Commands/GetQueryIdCommand.js +34 -0
- package/dist/hive/Commands/GetQueryIdCommand.js.map +1 -0
- package/dist/hive/Commands/GetResultSetMetadataCommand.d.ts +12 -0
- package/dist/hive/Commands/GetResultSetMetadataCommand.js +34 -0
- package/dist/hive/Commands/GetResultSetMetadataCommand.js.map +1 -0
- package/dist/hive/Commands/GetSchemasCommand.d.ts +14 -0
- package/dist/hive/Commands/GetSchemasCommand.js +34 -0
- package/dist/hive/Commands/GetSchemasCommand.js.map +1 -0
- package/dist/hive/Commands/GetTableTypesCommand.d.ts +12 -0
- package/dist/hive/Commands/GetTableTypesCommand.js +34 -0
- package/dist/hive/Commands/GetTableTypesCommand.js.map +1 -0
- package/dist/hive/Commands/GetTablesCommand.d.ts +16 -0
- package/dist/hive/Commands/GetTablesCommand.js +34 -0
- package/dist/hive/Commands/GetTablesCommand.js.map +1 -0
- package/dist/hive/Commands/GetTypeInfoCommand.d.ts +12 -0
- package/dist/hive/Commands/GetTypeInfoCommand.js +34 -0
- package/dist/hive/Commands/GetTypeInfoCommand.js.map +1 -0
- package/dist/hive/Commands/OpenSessionCommand.d.ts +33 -0
- package/dist/hive/Commands/OpenSessionCommand.js +34 -0
- package/dist/hive/Commands/OpenSessionCommand.js.map +1 -0
- package/dist/hive/Commands/RenewDelegationTokenCommand.d.ts +12 -0
- package/dist/hive/Commands/RenewDelegationTokenCommand.js +34 -0
- package/dist/hive/Commands/RenewDelegationTokenCommand.js.map +1 -0
- package/dist/hive/Commands/SetClientInfoCommand.d.ts +12 -0
- package/dist/hive/Commands/SetClientInfoCommand.js +34 -0
- package/dist/hive/Commands/SetClientInfoCommand.js.map +1 -0
- package/dist/hive/HiveDriver.d.ts +52 -0
- package/dist/hive/HiveDriver.js +129 -0
- package/dist/hive/HiveDriver.js.map +1 -0
- package/dist/hive/Types/index.d.ts +229 -0
- package/dist/hive/Types/index.js +16 -0
- package/dist/hive/Types/index.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/result/IOperationResult.d.ts +5 -0
- package/dist/result/IOperationResult.js +3 -0
- package/dist/result/IOperationResult.js.map +1 -0
- package/dist/result/JsonResult.d.ts +20 -0
- package/dist/result/JsonResult.js +137 -0
- package/dist/result/JsonResult.js.map +1 -0
- package/dist/result/NullResult.d.ts +6 -0
- package/dist/result/NullResult.js +13 -0
- package/dist/result/NullResult.js.map +1 -0
- package/dist/utils/GetResult.d.ts +16 -0
- package/dist/utils/GetResult.js +38 -0
- package/dist/utils/GetResult.js.map +1 -0
- package/dist/utils/HiveUtils.d.ts +11 -0
- package/dist/utils/HiveUtils.js +39 -0
- package/dist/utils/HiveUtils.js.map +1 -0
- package/dist/utils/ProgressUpdateTransformer.d.ts +8 -0
- package/dist/utils/ProgressUpdateTransformer.js +33 -0
- package/dist/utils/ProgressUpdateTransformer.js.map +1 -0
- package/dist/utils/WaitUntilReady.d.ts +16 -0
- package/dist/utils/WaitUntilReady.js +120 -0
- package/dist/utils/WaitUntilReady.js.map +1 -0
- package/docs/readme.md +227 -0
- package/docs/troubleshooting.md +84 -0
- package/examples/data_types.js +173 -0
- package/examples/repl +106 -0
- package/examples/session.js +55 -0
- package/examples/usage.js +18 -0
- package/nyc.config.js +8 -0
- package/package.json +56 -0
- package/tests/e2e/data_types.test.js +353 -0
- package/tests/e2e/utils/config.js +20 -0
- package/tests/e2e/utils/logger.js +22 -0
- package/tests/unit/HiveClient.test.js +153 -0
- package/tests/unit/HiveOperation.test.js +340 -0
- package/tests/unit/HiveSession.test.js +146 -0
- package/tests/unit/connection/auth/PlainHttpAuthentication.test.js +44 -0
- package/tests/unit/connection/connections/HttpConnection.test.js +141 -0
- package/tests/unit/dto/InfoValue.test.js +50 -0
- package/tests/unit/factory/StatusFactory.test.js +62 -0
- package/tests/unit/hive/HiveDriver.test.js +115 -0
- package/tests/unit/hive/commands/CancelDelegationTokenCommand.test.js +43 -0
- package/tests/unit/hive/commands/CancelOperationCommand.test.js +45 -0
- package/tests/unit/hive/commands/CloseOperationCommand.test.js +45 -0
- package/tests/unit/hive/commands/CloseSessionCommand.test.js +38 -0
- package/tests/unit/hive/commands/ExecuteStatementCommand.test.js +54 -0
- package/tests/unit/hive/commands/FetchResultsCommand.test.js +59 -0
- package/tests/unit/hive/commands/GetCatalogsCommand.test.js +50 -0
- package/tests/unit/hive/commands/GetColumnsCommand.test.js +50 -0
- package/tests/unit/hive/commands/GetCrossReferenceCommand.test.js +56 -0
- package/tests/unit/hive/commands/GetDelegationTokenCommand.test.js +45 -0
- package/tests/unit/hive/commands/GetFunctionsCommand.test.js +50 -0
- package/tests/unit/hive/commands/GetInfoCommand.test.js +51 -0
- package/tests/unit/hive/commands/GetOperationStatusCommand.test.js +63 -0
- package/tests/unit/hive/commands/GetPrimaryKeysCommand.test.js +50 -0
- package/tests/unit/hive/commands/GetQueryIdCommand.test.js +42 -0
- package/tests/unit/hive/commands/GetResultSetMetadataCommand.test.js +54 -0
- package/tests/unit/hive/commands/GetSchemasCommand.test.js +52 -0
- package/tests/unit/hive/commands/GetTableTypesCommand.test.js +50 -0
- package/tests/unit/hive/commands/GetTablesCommand.test.js +54 -0
- package/tests/unit/hive/commands/GetTypeInfoCommand.test.js +50 -0
- package/tests/unit/hive/commands/OpenSessionCommand.test.js +43 -0
- package/tests/unit/hive/commands/RenewDelegationTokenCommand.test.js +43 -0
- package/tests/unit/hive/commands/SetClientInfoCommand.test.js +45 -0
- package/tests/unit/result/JsonResult.test.js +295 -0
- package/tests/unit/utils/GetResult.test.js +30 -0
- package/tests/unit/utils/HiveUtils.test.js +60 -0
- package/tests/unit/utils/ProgressUpdateTransformer.test.js +28 -0
- package/tests/unit/utils/WaitUntilReady.test.js +105 -0
- package/thrift/TCLIService.thrift +1299 -0
- package/thrift/gen-nodejs/TCLIService.js +4596 -0
- package/thrift/gen-nodejs/TCLIService_types.js +6794 -0
- 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
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
|
+
};
|