Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/session_params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { DBSQLClient } = require('..');

const client = new DBSQLClient();

const host = process.env.DATABRICKS_HOST;
const path = process.env.DATABRICKS_HTTP_PATH;
const token = process.env.DATABRICKS_TOKEN;

client
.connect({ host, path, token })
.then(async (client) => {
const session = await client.openSession({
configuration: {
QUERY_TAGS: 'team:engineering,test:session-params,driver:node',
ansi_mode: 'false',
},
});

const op = await session.executeStatement('SELECT 1');
const rows = await op.fetchAll();
console.log(rows);
await op.close();

await session.close();
await client.close();
})
.catch((error) => {
console.log(error);
});
1 change: 1 addition & 0 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
const response = await this.driver.openSession({
client_protocol_i64: new Int64(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V8),
...getInitialNamespaceOptions(request.initialCatalog, request.initialSchema),
configuration: request.configuration,
canUseMultipleCatalogs: true,
});

Expand Down
1 change: 1 addition & 0 deletions lib/contracts/IDBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type ConnectionOptions = {
export interface OpenSessionRequest {
initialCatalog?: string;
initialSchema?: string;
configuration?: { [key: string]: string };
}

export default interface IDBSQLClient {
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/query_parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const openSession = async () => {
return connection.openSession({
initialCatalog: config.catalog,
initialSchema: config.schema,
configuration: {
QUERY_TAGS: 'test:e2e,driver:node',
},
});
};

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/DBSQLClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ describe('DBSQLClient.openSession', () => {
}
});

it('should pass session configuration to OpenSessionReq', async () => {
const client = new DBSQLClient();
const thriftClient = new ThriftClientStub();
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));

const configuration = { QUERY_TAGS: 'team:engineering', ansi_mode: 'true' };
await client.openSession({ configuration });
expect(thriftClient.openSessionReq?.configuration).to.deep.equal(configuration);
});

it('should affect session behavior based on protocol version', async () => {
const client = new DBSQLClient();
const thriftClient = new ThriftClientStub();
Expand Down
Loading