Skip to content

Commit a85ec43

Browse files
authored
[PECOBLR-675] support for session params (#307)
support for session params Signed-off-by: Sreekanth Vadigi <[email protected]>
1 parent 6b165ca commit a85ec43

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

examples/session_params.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { DBSQLClient } = require('..');
2+
3+
const client = new DBSQLClient();
4+
5+
const host = process.env.DATABRICKS_HOST;
6+
const path = process.env.DATABRICKS_HTTP_PATH;
7+
const token = process.env.DATABRICKS_TOKEN;
8+
9+
client
10+
.connect({ host, path, token })
11+
.then(async (client) => {
12+
const session = await client.openSession({
13+
configuration: {
14+
QUERY_TAGS: 'team:engineering,test:session-params,driver:node',
15+
ansi_mode: 'false',
16+
},
17+
});
18+
19+
const op = await session.executeStatement('SELECT 1');
20+
const rows = await op.fetchAll();
21+
console.log(rows);
22+
await op.close();
23+
24+
await session.close();
25+
await client.close();
26+
})
27+
.catch((error) => {
28+
console.log(error);
29+
});

lib/DBSQLClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
221221
const response = await this.driver.openSession({
222222
client_protocol_i64: new Int64(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V8),
223223
...getInitialNamespaceOptions(request.initialCatalog, request.initialSchema),
224+
configuration: request.configuration,
224225
canUseMultipleCatalogs: true,
225226
});
226227

lib/contracts/IDBSQLClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type ConnectionOptions = {
3838
export interface OpenSessionRequest {
3939
initialCatalog?: string;
4040
initialSchema?: string;
41+
configuration?: { [key: string]: string };
4142
}
4243

4344
export default interface IDBSQLClient {

tests/e2e/query_parameters.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const openSession = async () => {
1717
return connection.openSession({
1818
initialCatalog: config.catalog,
1919
initialSchema: config.schema,
20+
configuration: {
21+
QUERY_TAGS: 'test:e2e,driver:node',
22+
},
2023
});
2124
};
2225

tests/unit/DBSQLClient.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ describe('DBSQLClient.openSession', () => {
185185
}
186186
});
187187

188+
it('should pass session configuration to OpenSessionReq', async () => {
189+
const client = new DBSQLClient();
190+
const thriftClient = new ThriftClientStub();
191+
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));
192+
193+
const configuration = { QUERY_TAGS: 'team:engineering', ansi_mode: 'true' };
194+
await client.openSession({ configuration });
195+
expect(thriftClient.openSessionReq?.configuration).to.deep.equal(configuration);
196+
});
197+
188198
it('should affect session behavior based on protocol version', async () => {
189199
const client = new DBSQLClient();
190200
const thriftClient = new ThriftClientStub();

0 commit comments

Comments
 (0)