Skip to content

Commit 2f59bac

Browse files
committed
Add metric view metadata support
1 parent 3f2eec1 commit 2f59bac

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

lib/DBSQLClient.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
172172
}
173173
}
174174

175+
// Store enableMetricViewMetadata configuration
176+
if (options.enableMetricViewMetadata !== undefined) {
177+
this.config.enableMetricViewMetadata = options.enableMetricViewMetadata;
178+
}
179+
175180
this.authProvider = this.createAuthProvider(options, authProvider);
176181

177182
this.connectionProvider = this.createConnectionProvider(options);
@@ -218,10 +223,18 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
218223
* const session = await client.openSession();
219224
*/
220225
public async openSession(request: OpenSessionRequest = {}): Promise<IDBSQLSession> {
226+
// Prepare session configuration
227+
const configuration = request.configuration ? { ...request.configuration } : {};
228+
229+
// Add metric view metadata config if enabled
230+
if (this.config.enableMetricViewMetadata) {
231+
configuration['spark.sql.thriftserver.metadata.metricview.enabled'] = 'true';
232+
}
233+
221234
const response = await this.driver.openSession({
222235
client_protocol_i64: new Int64(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V8),
223236
...getInitialNamespaceOptions(request.initialCatalog, request.initialSchema),
224-
configuration: request.configuration,
237+
configuration,
225238
canUseMultipleCatalogs: true,
226239
});
227240

lib/contracts/IClientContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ClientConfig {
2121
cloudFetchSpeedThresholdMBps: number;
2222

2323
useLZ4Compression: boolean;
24+
enableMetricViewMetadata?: boolean;
2425
}
2526

2627
export default interface IClientContext {

lib/contracts/IDBSQLClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type ConnectionOptions = {
3333
userAgentEntry?: string;
3434
socketTimeout?: number;
3535
proxy?: ProxyOptions;
36+
enableMetricViewMetadata?: boolean;
3637
} & AuthOptions;
3738

3839
export interface OpenSessionRequest {

tests/unit/DBSQLClient.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,80 @@ describe('DBSQLClient.createAuthProvider', () => {
560560
expect(provider).to.be.equal(customProvider);
561561
});
562562
});
563+
564+
describe('DBSQLClient.enableMetricViewMetadata', () => {
565+
it('should store enableMetricViewMetadata config when enabled', async () => {
566+
const client = new DBSQLClient();
567+
568+
expect(client.getConfig().enableMetricViewMetadata).to.be.undefined;
569+
570+
await client.connect({ ...connectOptions, enableMetricViewMetadata: true });
571+
572+
expect(client.getConfig().enableMetricViewMetadata).to.be.true;
573+
});
574+
575+
it('should not store enableMetricViewMetadata config when disabled', async () => {
576+
const client = new DBSQLClient();
577+
578+
expect(client.getConfig().enableMetricViewMetadata).to.be.undefined;
579+
580+
await client.connect({ ...connectOptions, enableMetricViewMetadata: false });
581+
582+
expect(client.getConfig().enableMetricViewMetadata).to.be.false;
583+
});
584+
585+
it('should inject session parameter when enableMetricViewMetadata is true', async () => {
586+
const client = new DBSQLClient();
587+
const thriftClient = new ThriftClientStub();
588+
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));
589+
590+
await client.connect({ ...connectOptions, enableMetricViewMetadata: true });
591+
await client.openSession();
592+
593+
expect(thriftClient.openSessionReq?.configuration).to.have.property(
594+
'spark.sql.thriftserver.metadata.metricview.enabled',
595+
'true',
596+
);
597+
});
598+
599+
it('should not inject session parameter when enableMetricViewMetadata is false', async () => {
600+
const client = new DBSQLClient();
601+
const thriftClient = new ThriftClientStub();
602+
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));
603+
604+
await client.connect({ ...connectOptions, enableMetricViewMetadata: false });
605+
await client.openSession();
606+
607+
expect(thriftClient.openSessionReq?.configuration).to.not.have.property(
608+
'spark.sql.thriftserver.metadata.metricview.enabled',
609+
);
610+
});
611+
612+
it('should not inject session parameter when enableMetricViewMetadata is not set', async () => {
613+
const client = new DBSQLClient();
614+
const thriftClient = new ThriftClientStub();
615+
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));
616+
617+
await client.connect(connectOptions);
618+
await client.openSession();
619+
620+
expect(thriftClient.openSessionReq?.configuration).to.not.have.property(
621+
'spark.sql.thriftserver.metadata.metricview.enabled',
622+
);
623+
});
624+
625+
it('should preserve user-provided session configuration', async () => {
626+
const client = new DBSQLClient();
627+
const thriftClient = new ThriftClientStub();
628+
sinon.stub(client, 'getClient').returns(Promise.resolve(thriftClient));
629+
630+
await client.connect({ ...connectOptions, enableMetricViewMetadata: true });
631+
const userConfig = { QUERY_TAGS: 'team:engineering', ansi_mode: 'true' };
632+
await client.openSession({ configuration: userConfig });
633+
634+
expect(thriftClient.openSessionReq?.configuration).to.deep.equal({
635+
...userConfig,
636+
'spark.sql.thriftserver.metadata.metricview.enabled': 'true',
637+
});
638+
});
639+
});

0 commit comments

Comments
 (0)