@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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const GetTypeInfoCommand = require('../../../../dist/hive/Commands/GetTypeInfoCommand').default;
|
|
3
|
+
|
|
4
|
+
const requestMock = {
|
|
5
|
+
sessionHandle: {
|
|
6
|
+
sessionId: { guid: '', secret: '' }
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const TCLIService_types = {
|
|
11
|
+
TGetTypeInfoReq: function (options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
|
|
14
|
+
expect(options).to.be.deep.eq(requestMock);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const GET_TYPE_INFO = 1;
|
|
19
|
+
|
|
20
|
+
const responseMock = {
|
|
21
|
+
status: { statusCode: 0 },
|
|
22
|
+
operationHandle: {
|
|
23
|
+
hasResultSet: true,
|
|
24
|
+
operationId: { guid: '', secret: '' },
|
|
25
|
+
operationType: GET_TYPE_INFO,
|
|
26
|
+
modifiedRowCount: 0
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const thriftClientMock = {
|
|
30
|
+
GetTypeInfo(request, callback) {
|
|
31
|
+
return callback(null, responseMock);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe('GetTypeInfoCommand', () => {
|
|
36
|
+
it('should return response', (cb) => {
|
|
37
|
+
const command = new GetTypeInfoCommand(
|
|
38
|
+
thriftClientMock,
|
|
39
|
+
TCLIService_types
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
command.execute(requestMock)
|
|
43
|
+
.then(response => {
|
|
44
|
+
expect(response).to.be.deep.eq(responseMock);
|
|
45
|
+
cb();
|
|
46
|
+
}).catch(error => {
|
|
47
|
+
cb(error);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const OpenSessionCommand = require('../../../../dist/hive/Commands/OpenSessionCommand').default;
|
|
3
|
+
|
|
4
|
+
const CLIENT_PROTOCOL = 8;
|
|
5
|
+
|
|
6
|
+
const TCLIService_types = {
|
|
7
|
+
TOpenSessionReq: function (options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
|
|
10
|
+
expect(options.client_protocol).to.be.eq(CLIENT_PROTOCOL);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const responseMock = {
|
|
14
|
+
status: { statusCode: 0 },
|
|
15
|
+
serverProtocolVersion: CLIENT_PROTOCOL,
|
|
16
|
+
sessionHandle: {
|
|
17
|
+
sessionId: { guid: '', secret: '' }
|
|
18
|
+
},
|
|
19
|
+
configuration: {}
|
|
20
|
+
};
|
|
21
|
+
const thriftClientMock = {
|
|
22
|
+
OpenSession(request, callback) {
|
|
23
|
+
return callback(null, responseMock);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('OpenSessionCommand', () => {
|
|
28
|
+
it('should return response', (cb) => {
|
|
29
|
+
const command = new OpenSessionCommand(
|
|
30
|
+
thriftClientMock,
|
|
31
|
+
TCLIService_types
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
command.execute({
|
|
35
|
+
client_protocol: CLIENT_PROTOCOL
|
|
36
|
+
}).then(response => {
|
|
37
|
+
expect(response).to.be.deep.eq(responseMock);
|
|
38
|
+
cb();
|
|
39
|
+
}).catch(error => {
|
|
40
|
+
cb(error);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const RenewDelegationTokenCommand = require('../../../../dist/hive/Commands/RenewDelegationTokenCommand').default;
|
|
3
|
+
|
|
4
|
+
const requestMock = {
|
|
5
|
+
sessionHandle: {
|
|
6
|
+
sessionId: { guid: '', secret: '' }
|
|
7
|
+
},
|
|
8
|
+
delegationToken: 'token'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const TCLIService_types = {
|
|
12
|
+
TRenewDelegationTokenReq: function (options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
|
|
15
|
+
expect(options).to.be.deep.eq(requestMock);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const responseMock = {
|
|
20
|
+
status: { statusCode: 0 },
|
|
21
|
+
};
|
|
22
|
+
const thriftClientMock = {
|
|
23
|
+
RenewDelegationToken(request, callback) {
|
|
24
|
+
return callback(null, responseMock);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('RenewDelegationTokenCommand', () => {
|
|
29
|
+
it('should return response', (cb) => {
|
|
30
|
+
const command = new RenewDelegationTokenCommand(
|
|
31
|
+
thriftClientMock,
|
|
32
|
+
TCLIService_types
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
command.execute(requestMock)
|
|
36
|
+
.then(response => {
|
|
37
|
+
expect(response).to.be.deep.eq(responseMock);
|
|
38
|
+
cb();
|
|
39
|
+
}).catch(error => {
|
|
40
|
+
cb(error);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const SetClientInfoCommand = require('../../../../dist/hive/Commands/SetClientInfoCommand').default;
|
|
3
|
+
|
|
4
|
+
const requestMock = {
|
|
5
|
+
sessionHandle: {
|
|
6
|
+
sessionId: { guid: '', secret: '' }
|
|
7
|
+
},
|
|
8
|
+
configuration: {
|
|
9
|
+
param: 'value'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const TCLIService_types = {
|
|
14
|
+
TSetClientInfoReq: function (options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
|
|
17
|
+
expect(options).to.be.deep.eq(requestMock);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const responseMock = {
|
|
22
|
+
status: { statusCode: 0 }
|
|
23
|
+
};
|
|
24
|
+
const thriftClientMock = {
|
|
25
|
+
SetClientInfo(request, callback) {
|
|
26
|
+
return callback(null, responseMock);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('SetClientInfoCommand', () => {
|
|
31
|
+
it('should return response', (cb) => {
|
|
32
|
+
const command = new SetClientInfoCommand(
|
|
33
|
+
thriftClientMock,
|
|
34
|
+
TCLIService_types
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
command.execute(requestMock)
|
|
38
|
+
.then(response => {
|
|
39
|
+
expect(response).to.be.deep.eq(responseMock);
|
|
40
|
+
cb();
|
|
41
|
+
}).catch(error => {
|
|
42
|
+
cb(error);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const JsonResult = require('../../../dist/result/JsonResult').default;
|
|
3
|
+
const { TCLIService_types } = require('../../../').thrift;
|
|
4
|
+
const Int64 = require('node-int64');
|
|
5
|
+
|
|
6
|
+
const getColumnSchema = (name, type, position) => {
|
|
7
|
+
return {
|
|
8
|
+
columnName: name,
|
|
9
|
+
typeDesc: {
|
|
10
|
+
types: [{
|
|
11
|
+
primitiveEntry: {
|
|
12
|
+
type
|
|
13
|
+
}
|
|
14
|
+
}]
|
|
15
|
+
},
|
|
16
|
+
position
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('JsonResult', () => {
|
|
21
|
+
it('should convert schema with primitive types to json', () => {
|
|
22
|
+
const schema = {
|
|
23
|
+
columns: [
|
|
24
|
+
getColumnSchema('table.str', TCLIService_types.TTypeId.STRING_TYPE, 1),
|
|
25
|
+
getColumnSchema('table.int64', TCLIService_types.TTypeId.BIGINT_TYPE, 2),
|
|
26
|
+
getColumnSchema('table.bin', TCLIService_types.TTypeId.BINARY_TYPE, 3),
|
|
27
|
+
getColumnSchema('table.bool', TCLIService_types.TTypeId.BOOLEAN_TYPE, 4),
|
|
28
|
+
getColumnSchema('table.char', TCLIService_types.TTypeId.CHAR_TYPE, 5),
|
|
29
|
+
getColumnSchema('table.dbl', TCLIService_types.TTypeId.DOUBLE_TYPE, 6),
|
|
30
|
+
getColumnSchema('table.flt', TCLIService_types.TTypeId.FLOAT_TYPE, 7),
|
|
31
|
+
getColumnSchema('table.int', TCLIService_types.TTypeId.INT_TYPE, 8),
|
|
32
|
+
getColumnSchema('table.small_int', TCLIService_types.TTypeId.SMALLINT_TYPE, 9),
|
|
33
|
+
getColumnSchema('table.tiny_int', TCLIService_types.TTypeId.TINYINT_TYPE, 10),
|
|
34
|
+
getColumnSchema('table.varch', TCLIService_types.TTypeId.VARCHAR_TYPE, 11),
|
|
35
|
+
getColumnSchema('table.dec', TCLIService_types.TTypeId.DECIMAL_TYPE, 12),
|
|
36
|
+
getColumnSchema('table.ts', TCLIService_types.TTypeId.TIMESTAMP_TYPE, 13),
|
|
37
|
+
getColumnSchema('table.date', TCLIService_types.TTypeId.DATE_TYPE, 14),
|
|
38
|
+
getColumnSchema('table.day_interval', TCLIService_types.TTypeId.INTERVAL_DAY_TIME_TYPE, 15),
|
|
39
|
+
getColumnSchema('table.month_interval', TCLIService_types.TTypeId.INTERVAL_YEAR_MONTH_TYPE, 16),
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
const data = [
|
|
43
|
+
{
|
|
44
|
+
columns: [{
|
|
45
|
+
stringVal: { values: ['a', 'b'] }
|
|
46
|
+
}, {
|
|
47
|
+
i64Val: { values: [new Int64(Buffer.from([0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])), new Int64(Buffer.from([0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02]))] }
|
|
48
|
+
}, {
|
|
49
|
+
binaryVal: { values: [Buffer.from([1]), Buffer.from([2])] }
|
|
50
|
+
}, {
|
|
51
|
+
boolVal: { values: [true, false] }
|
|
52
|
+
}, {
|
|
53
|
+
stringVal: { values: ['c', 'd'] }
|
|
54
|
+
}, {
|
|
55
|
+
doubleVal: { values: [1.2, 1.3] }
|
|
56
|
+
}, {
|
|
57
|
+
doubleVal: { values: [2.2, 2.3] }
|
|
58
|
+
}, {
|
|
59
|
+
i32Val: { values: [1, 2] }
|
|
60
|
+
}, {
|
|
61
|
+
i16Val: { values: [3, 4] }
|
|
62
|
+
}, {
|
|
63
|
+
byteVal: { values: [5, 6] }
|
|
64
|
+
}, {
|
|
65
|
+
stringVal: { values: ['e', 'f'] }
|
|
66
|
+
}, {
|
|
67
|
+
stringVal: { values: ['2.1', '2.2'] }
|
|
68
|
+
}, {
|
|
69
|
+
stringVal: { values: ['2020-01-17 00:17:13.0', '2020-01-17 00:17:13.0'] }
|
|
70
|
+
}, {
|
|
71
|
+
stringVal: { values: ['2020-01-17', '2020-01-17'] }
|
|
72
|
+
}, {
|
|
73
|
+
stringVal: { values: ['1 00:00:00.000000000', '1 00:00:00.000000000'] }
|
|
74
|
+
}, {
|
|
75
|
+
stringVal: { values: ['0-1', '0-1'] }
|
|
76
|
+
}]
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = new JsonResult(TCLIService_types);
|
|
81
|
+
result.setOperation({
|
|
82
|
+
getSchema: () => schema,
|
|
83
|
+
getData: () => data,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(result.getValue()).to.be.deep.eq([{
|
|
87
|
+
"str":"a",
|
|
88
|
+
"int64":282578800148737,
|
|
89
|
+
"bin": Buffer.from([1]),
|
|
90
|
+
"bool":true,
|
|
91
|
+
"char":"c",
|
|
92
|
+
"dbl":1.2,
|
|
93
|
+
"flt":2.2,
|
|
94
|
+
"int":1,
|
|
95
|
+
"small_int":3,
|
|
96
|
+
"tiny_int":5,
|
|
97
|
+
"varch":"e",
|
|
98
|
+
"dec": 2.1,
|
|
99
|
+
"ts": "2020-01-17 00:17:13.0",
|
|
100
|
+
"date": "2020-01-17",
|
|
101
|
+
"day_interval": "1 00:00:00.000000000",
|
|
102
|
+
"month_interval": "0-1",
|
|
103
|
+
}, {
|
|
104
|
+
"str":"b",
|
|
105
|
+
"int64":565157600297474,
|
|
106
|
+
"bin":Buffer.from([2]),
|
|
107
|
+
"bool":false,
|
|
108
|
+
"char":"d",
|
|
109
|
+
"dbl":1.3,
|
|
110
|
+
"flt":2.3,
|
|
111
|
+
"int":2,
|
|
112
|
+
"small_int":4,
|
|
113
|
+
"tiny_int":6,
|
|
114
|
+
"varch":"f",
|
|
115
|
+
"dec": 2.2,
|
|
116
|
+
"ts": "2020-01-17 00:17:13.0",
|
|
117
|
+
"date": "2020-01-17",
|
|
118
|
+
"day_interval": "1 00:00:00.000000000",
|
|
119
|
+
"month_interval": "0-1",
|
|
120
|
+
}]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should convert complex types', () => {
|
|
124
|
+
const schema = {
|
|
125
|
+
columns: [
|
|
126
|
+
getColumnSchema('table.array', TCLIService_types.TTypeId.ARRAY_TYPE, 1),
|
|
127
|
+
getColumnSchema('table.map', TCLIService_types.TTypeId.MAP_TYPE, 2),
|
|
128
|
+
getColumnSchema('table.struct', TCLIService_types.TTypeId.STRUCT_TYPE, 3),
|
|
129
|
+
getColumnSchema('table.union', TCLIService_types.TTypeId.UNION_TYPE, 4)
|
|
130
|
+
]
|
|
131
|
+
};
|
|
132
|
+
const data = [
|
|
133
|
+
{
|
|
134
|
+
columns: [{
|
|
135
|
+
stringVal: { values: ['["a", "b"]', '["c", "d"]'] }
|
|
136
|
+
}, {
|
|
137
|
+
stringVal: { values: ['{ "key": 12 }', '{ "key": 13 }'] }
|
|
138
|
+
}, {
|
|
139
|
+
stringVal: { values: ['{ "name": "Jon", "surname": "Doe" }', '{ "name": "Jane", "surname": "Doe" }'] }
|
|
140
|
+
}, {
|
|
141
|
+
stringVal: { values: ['{0:12}', '{1:"foo"}'] }
|
|
142
|
+
}]
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
const result = new JsonResult(TCLIService_types);
|
|
147
|
+
result.setOperation({
|
|
148
|
+
getSchema: () => schema,
|
|
149
|
+
getData: () => data,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(result.getValue()).to.be.deep.eq([{
|
|
153
|
+
array: ["a", "b"],
|
|
154
|
+
map: { "key": 12 },
|
|
155
|
+
struct: { "name": "Jon", "surname": "Doe" },
|
|
156
|
+
union: '{0:12}',
|
|
157
|
+
}, {
|
|
158
|
+
array: ["c", "d"],
|
|
159
|
+
map: { "key": 13 },
|
|
160
|
+
struct: { "name": "Jane", "surname": "Doe" },
|
|
161
|
+
union: '{1:"foo"}',
|
|
162
|
+
}]);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should merge data items', () => {
|
|
166
|
+
const schema = {
|
|
167
|
+
columns: [
|
|
168
|
+
getColumnSchema('table.id', TCLIService_types.TTypeId.STRING_TYPE, 1),
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
const data = [
|
|
172
|
+
{
|
|
173
|
+
columns: [{
|
|
174
|
+
stringVal: { values: ['0', '1'] }
|
|
175
|
+
}]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
columns: [{
|
|
179
|
+
stringVal: { values: ['2', '3'] }
|
|
180
|
+
}]
|
|
181
|
+
}
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const result = new JsonResult(TCLIService_types);
|
|
185
|
+
result.setOperation({
|
|
186
|
+
getSchema: () => schema,
|
|
187
|
+
getData: () => data,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(result.getValue()).to.be.deep.eq([
|
|
191
|
+
{ id: "0" },
|
|
192
|
+
{ id: "1" },
|
|
193
|
+
{ id: "2" },
|
|
194
|
+
{ id: "3" },
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should detect nulls', () => {
|
|
199
|
+
const result = new JsonResult(TCLIService_types);
|
|
200
|
+
const buf = Buffer.from([0x55, 0xAA, 0xC3]);
|
|
201
|
+
|
|
202
|
+
[
|
|
203
|
+
true, false, true, false, true, false, true, false, // 0x55
|
|
204
|
+
false, true, false, true, false, true, false, true, // 0xAA,
|
|
205
|
+
true, true, false, false, false, false, true, true, // 0xC3
|
|
206
|
+
].forEach((value, i) => {
|
|
207
|
+
expect(result.isNull(buf, i), i).to.be.eq(value);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should detect nulls for each type', () => {
|
|
212
|
+
const schema = {
|
|
213
|
+
columns: [
|
|
214
|
+
getColumnSchema('table.str', TCLIService_types.TTypeId.STRING_TYPE, 1),
|
|
215
|
+
getColumnSchema('table.int64', TCLIService_types.TTypeId.BIGINT_TYPE, 2),
|
|
216
|
+
getColumnSchema('table.bin', TCLIService_types.TTypeId.BINARY_TYPE, 3),
|
|
217
|
+
getColumnSchema('table.bool', TCLIService_types.TTypeId.BOOLEAN_TYPE, 4),
|
|
218
|
+
getColumnSchema('table.char', TCLIService_types.TTypeId.CHAR_TYPE, 5),
|
|
219
|
+
getColumnSchema('table.dbl', TCLIService_types.TTypeId.DOUBLE_TYPE, 6),
|
|
220
|
+
getColumnSchema('table.flt', TCLIService_types.TTypeId.FLOAT_TYPE, 7),
|
|
221
|
+
getColumnSchema('table.int', TCLIService_types.TTypeId.INT_TYPE, 8),
|
|
222
|
+
getColumnSchema('table.small_int', TCLIService_types.TTypeId.SMALLINT_TYPE, 9),
|
|
223
|
+
getColumnSchema('table.tiny_int', TCLIService_types.TTypeId.TINYINT_TYPE, 10),
|
|
224
|
+
getColumnSchema('table.varch', TCLIService_types.TTypeId.VARCHAR_TYPE, 11),
|
|
225
|
+
getColumnSchema('table.dec', TCLIService_types.TTypeId.DECIMAL_TYPE, 12),
|
|
226
|
+
getColumnSchema('table.ts', TCLIService_types.TTypeId.TIMESTAMP_TYPE, 13),
|
|
227
|
+
getColumnSchema('table.date', TCLIService_types.TTypeId.DATE_TYPE, 14),
|
|
228
|
+
getColumnSchema('table.day_interval', TCLIService_types.TTypeId.INTERVAL_DAY_TIME_TYPE, 15),
|
|
229
|
+
getColumnSchema('table.month_interval', TCLIService_types.TTypeId.INTERVAL_YEAR_MONTH_TYPE, 16),
|
|
230
|
+
]
|
|
231
|
+
};
|
|
232
|
+
const data = [
|
|
233
|
+
{
|
|
234
|
+
columns: [{
|
|
235
|
+
stringVal: { values: ['a'], nulls: Buffer.from([0x01]) }
|
|
236
|
+
}, {
|
|
237
|
+
i64Val: { values: [new Int64(Buffer.from([0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]))], nulls: Buffer.from([0x01]) }
|
|
238
|
+
}, {
|
|
239
|
+
binaryVal: { values: [Buffer.from([1])], nulls: Buffer.from([0x01]) }
|
|
240
|
+
}, {
|
|
241
|
+
boolVal: { values: [true], nulls: Buffer.from([0x01]) }
|
|
242
|
+
}, {
|
|
243
|
+
stringVal: { values: ['c'], nulls: Buffer.from([0x01]) }
|
|
244
|
+
}, {
|
|
245
|
+
doubleVal: { values: [1.2], nulls: Buffer.from([0x01]) }
|
|
246
|
+
}, {
|
|
247
|
+
doubleVal: { values: [2.2], nulls: Buffer.from([0x01]) }
|
|
248
|
+
}, {
|
|
249
|
+
i32Val: { values: [1], nulls: Buffer.from([0x01]) }
|
|
250
|
+
}, {
|
|
251
|
+
i16Val: { values: [3], nulls: Buffer.from([0x01]) }
|
|
252
|
+
}, {
|
|
253
|
+
byteVal: { values: [5], nulls: Buffer.from([0x01]) }
|
|
254
|
+
}, {
|
|
255
|
+
stringVal: { values: ['e'], nulls: Buffer.from([0x01]) }
|
|
256
|
+
}, {
|
|
257
|
+
stringVal: { values: ['2.1'], nulls: Buffer.from([0x01]) }
|
|
258
|
+
}, {
|
|
259
|
+
stringVal: { values: ['2020-01-17 00:17:13.0'], nulls: Buffer.from([0x01]) }
|
|
260
|
+
}, {
|
|
261
|
+
stringVal: { values: ['2020-01-17'], nulls: Buffer.from([0x01]) }
|
|
262
|
+
}, {
|
|
263
|
+
stringVal: { values: ['1 00:00:00.000000000'], nulls: Buffer.from([0x01]) }
|
|
264
|
+
}, {
|
|
265
|
+
stringVal: { values: ['0-1'], nulls: Buffer.from([0x01]) }
|
|
266
|
+
}]
|
|
267
|
+
}
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
const result = new JsonResult(TCLIService_types);
|
|
271
|
+
result.setOperation({
|
|
272
|
+
getSchema: () => schema,
|
|
273
|
+
getData: () => data,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
expect(result.getValue()).to.be.deep.eq([{
|
|
277
|
+
"str": null,
|
|
278
|
+
"int64": null,
|
|
279
|
+
"bin": null,
|
|
280
|
+
"bool": null,
|
|
281
|
+
"char": null,
|
|
282
|
+
"dbl": null,
|
|
283
|
+
"flt": null,
|
|
284
|
+
"int": null,
|
|
285
|
+
"small_int": null,
|
|
286
|
+
"tiny_int": null,
|
|
287
|
+
"varch": null,
|
|
288
|
+
"dec": null,
|
|
289
|
+
"ts": null,
|
|
290
|
+
"date": null,
|
|
291
|
+
"day_interval": null,
|
|
292
|
+
"month_interval": null,
|
|
293
|
+
}]);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const GetResult = require('../../../dist/utils/GetResult').default;
|
|
3
|
+
const NullResult = require('../../../dist/result/NullResult').default;
|
|
4
|
+
const JsonResult = require('../../../dist/result/JsonResult').default;
|
|
5
|
+
|
|
6
|
+
describe('GetResult', () => {
|
|
7
|
+
it('should return null result', () => {
|
|
8
|
+
const t = new GetResult({
|
|
9
|
+
getSchema: () => null
|
|
10
|
+
});
|
|
11
|
+
expect(t.execute()).instanceOf(NullResult);
|
|
12
|
+
});
|
|
13
|
+
it('should return json result', () => {
|
|
14
|
+
const t = new GetResult({
|
|
15
|
+
getSchema: () => {},
|
|
16
|
+
getData: () => []
|
|
17
|
+
});
|
|
18
|
+
expect(t.execute()).instanceOf(JsonResult);
|
|
19
|
+
});
|
|
20
|
+
it('should return custom result', () => {
|
|
21
|
+
const customResult = {
|
|
22
|
+
setOperation() {
|
|
23
|
+
this.executed = true;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const t = new GetResult({});
|
|
27
|
+
expect(t.execute(customResult)).to.be.eq(customResult);
|
|
28
|
+
expect(customResult.executed).to.be.true;
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const HiveUtils = require('../../../dist/utils/HiveUtils').default;
|
|
3
|
+
const NullResult = require('../../../dist/result/NullResult').default;
|
|
4
|
+
const { TCLIService_types } = require('../../../').thrift;
|
|
5
|
+
|
|
6
|
+
describe('HiveUtils', () => {
|
|
7
|
+
it('waitUntilReady', () => {
|
|
8
|
+
const operation = {
|
|
9
|
+
status: () => Promise.resolve({
|
|
10
|
+
operationState: 2
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
const utils = new HiveUtils(TCLIService_types);
|
|
14
|
+
let executed = false;
|
|
15
|
+
|
|
16
|
+
return utils.waitUntilReady(operation, true, () => {
|
|
17
|
+
executed = true;
|
|
18
|
+
}).then((op) => {
|
|
19
|
+
expect(executed).to.be.true;
|
|
20
|
+
expect(op).to.be.eq(operation);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('getResult', () => {
|
|
25
|
+
const utils = new HiveUtils(TCLIService_types);
|
|
26
|
+
const result = utils.getResult({
|
|
27
|
+
getSchema: () => null
|
|
28
|
+
});
|
|
29
|
+
expect(result).instanceOf(NullResult);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('fetchAll', () => {
|
|
33
|
+
const utils = new HiveUtils(TCLIService_types);
|
|
34
|
+
const operation = {
|
|
35
|
+
n: 0,
|
|
36
|
+
_hasMoreRows: true,
|
|
37
|
+
fetch() {
|
|
38
|
+
this.n++;
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
},
|
|
41
|
+
hasMoreRows() {
|
|
42
|
+
const result = this._hasMoreRows;
|
|
43
|
+
this._hasMoreRows = false;
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return utils.fetchAll(operation).then((operation) => {
|
|
48
|
+
expect(operation.n).to.be.eq(2);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('formatProgress', () => {
|
|
53
|
+
const utils = new HiveUtils(TCLIService_types);
|
|
54
|
+
const result = utils.formatProgress({
|
|
55
|
+
headerNames: [],
|
|
56
|
+
rows: []
|
|
57
|
+
});
|
|
58
|
+
expect(result).to.be.eq('\n');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const ProgressUpdateTransformer = require('../../../dist/utils/ProgressUpdateTransformer').default;
|
|
3
|
+
|
|
4
|
+
describe('ProgressUpdateTransformer', () => {
|
|
5
|
+
it('should have equal columns', () => {
|
|
6
|
+
const t = new ProgressUpdateTransformer();
|
|
7
|
+
|
|
8
|
+
expect(t.formatRow(['Column 1', 'Column 2'])).to.be.eq('Column 1 |Column 2 ');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should format response as table', () => {
|
|
12
|
+
const t = new ProgressUpdateTransformer({
|
|
13
|
+
headerNames: ['Column 1', 'Column 2'],
|
|
14
|
+
rows: [
|
|
15
|
+
[ 'value 1.1', 'value 1.2' ],
|
|
16
|
+
[ 'value 2.1', 'value 2.2' ]
|
|
17
|
+
],
|
|
18
|
+
footerSummary: 'footer'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(String(t)).to.be.eq(
|
|
22
|
+
'Column 1 |Column 2 \n' +
|
|
23
|
+
'value 1.1 |value 1.2 \n' +
|
|
24
|
+
'value 2.1 |value 2.2 \n' +
|
|
25
|
+
'footer'
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
});
|