Skip to content

Commit 7f5dcc9

Browse files
committed
fix(metadata): preserve public primary-key request contract
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent 625a7fe commit 7f5dcc9

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎lib/contracts/IDBSQLSession.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export type FunctionsRequest = {
122122
};
123123

124124
export type PrimaryKeysRequest = {
125-
catalogName?: string | null;
126-
schemaName?: string | null;
125+
catalogName?: string;
126+
schemaName: string;
127127
tableName: string;
128128
/**
129129
* @deprecated This option is no longer supported and will be removed in future releases

‎lib/thrift-backend/ThriftSessionBackend.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ export default class ThriftSessionBackend implements ISessionBackend {
302302
const driver = await this.context.getDriver();
303303
const response = await driver.getPrimaryKeys({
304304
sessionHandle: this.sessionHandle,
305-
catalogName: request.catalogName ?? undefined,
306-
schemaName: request.schemaName ?? undefined,
305+
catalogName: request.catalogName,
306+
schemaName: request.schemaName,
307307
tableName: request.tableName,
308308
runAsync: this.getRunAsyncForMetadataOperations(),
309309
...getDirectResultsOptions(request.maxRows, this.context.getConfig()),

‎tests/unit/DBSQLSession.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DBSQLSession, { numberToInt64 } from '../../lib/DBSQLSession';
55
import InfoValue from '../../lib/dto/InfoValue';
66
import Status from '../../lib/dto/Status';
77
import DBSQLOperation from '../../lib/DBSQLOperation';
8+
import { PrimaryKeysRequest } from '../../lib/contracts/IDBSQLSession';
89
import ISessionBackend from '../../lib/contracts/ISessionBackend';
910
import ParameterError from '../../lib/errors/ParameterError';
1011
import { TSessionHandle, TProtocolVersion } from '../../thrift/TCLIService_types';
@@ -514,16 +515,20 @@ describe('DBSQLSession', () => {
514515
});
515516

516517
describe('getPrimaryKeys', () => {
517-
it('should omit null namespace fields and preserve empty strings for Thrift', async () => {
518+
it('should forward null, omitted, and empty namespace names unchanged for Thrift', async () => {
518519
for (const catalogName of [undefined, null, '', 'catalog']) {
519520
for (const schemaName of [undefined, null, '', 'schema']) {
520521
const context = new ClientContextStub();
521522
const session = createSessionForTest({ handle: sessionHandleStub, context });
522523
// eslint-disable-next-line no-await-in-loop
523-
const result = await session.getPrimaryKeys({ catalogName, schemaName, tableName: 't1' });
524+
const result = await session.getPrimaryKeys({
525+
catalogName,
526+
schemaName,
527+
tableName: 't1',
528+
} as PrimaryKeysRequest);
524529
expect(result).instanceOf(DBSQLOperation);
525-
expect(context.driver.getPrimaryKeysReq?.catalogName).to.equal(catalogName ?? undefined);
526-
expect(context.driver.getPrimaryKeysReq?.schemaName).to.equal(schemaName ?? undefined);
530+
expect(context.driver.getPrimaryKeysReq?.catalogName).to.equal(catalogName);
531+
expect(context.driver.getPrimaryKeysReq?.schemaName).to.equal(schemaName);
527532
expect(context.driver.getPrimaryKeysReq?.tableName).to.equal('t1');
528533
}
529534
}

‎tests/unit/kernel/execution.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import KernelSessionBackend from '../../../lib/kernel/KernelSessionBackend';
2121
import KernelOperationBackend from '../../../lib/kernel/KernelOperationBackend';
2222
import { KernelNativeBinding, KernelConnection, KernelStatement } from '../../../lib/kernel/KernelNativeLoader';
2323
import IClientContext, { ClientConfig } from '../../../lib/contracts/IClientContext';
24+
import { PrimaryKeysRequest } from '../../../lib/contracts/IDBSQLSession';
2425
import IDBSQLLogger, { LogLevel } from '../../../lib/contracts/IDBSQLLogger';
2526
import HiveDriverError from '../../../lib/errors/HiveDriverError';
2627
import ParameterError from '../../../lib/errors/ParameterError';
@@ -1101,7 +1102,11 @@ describe('KernelSessionBackend', () => {
11011102
for (const catalogName of [undefined, null, '', 'main']) {
11021103
for (const schemaName of [undefined, null, '', 'def']) {
11031104
// eslint-disable-next-line no-await-in-loop
1104-
const operation = await session.getPrimaryKeys({ catalogName, schemaName, tableName: 't' });
1105+
const operation = await session.getPrimaryKeys({
1106+
catalogName,
1107+
schemaName,
1108+
tableName: 't',
1109+
} as PrimaryKeysRequest);
11051110
expect(operation).to.be.instanceOf(KernelOperationBackend);
11061111
expected.push(['getPrimaryKeys', catalogName, schemaName, 't']);
11071112
}

0 commit comments

Comments
 (0)