@@ -12,6 +12,8 @@ import {
1212 TSparkDirectResults ,
1313 TSparkArrowTypes ,
1414 TSparkParameter ,
15+ TProtocolVersion ,
16+ TExecuteStatementReq ,
1517} from '../thrift/TCLIService_types' ;
1618import IDBSQLSession , {
1719 ExecuteStatementOptions ,
@@ -29,7 +31,7 @@ import IOperation from './contracts/IOperation';
2931import DBSQLOperation from './DBSQLOperation' ;
3032import Status from './dto/Status' ;
3133import InfoValue from './dto/InfoValue' ;
32- import { definedOrError , LZ4 } from './utils' ;
34+ import { definedOrError , LZ4 , ProtocolVersion } from './utils' ;
3335import CloseableCollection from './utils/CloseableCollection' ;
3436import { LogLevel } from './contracts/IDBSQLLogger' ;
3537import HiveDriverError from './errors/HiveDriverError' ;
@@ -74,13 +76,13 @@ function getDirectResultsOptions(maxRows: number | bigint | Int64 | null | undef
7476 } ;
7577}
7678
77- function getArrowOptions ( config : ClientConfig ) : {
79+ function getArrowOptions ( config : ClientConfig , serverProtocolVersion : TProtocolVersion | undefined | null ) : {
7880 canReadArrowResult : boolean ;
7981 useArrowNativeTypes ?: TSparkArrowTypes ;
8082} {
8183 const { arrowEnabled = true , useArrowNativeTypes = true } = config ;
8284
83- if ( ! arrowEnabled ) {
85+ if ( ! arrowEnabled || ! ProtocolVersion . supportsArrowMetadata ( serverProtocolVersion ) ) {
8486 return {
8587 canReadArrowResult : false ,
8688 } ;
@@ -136,6 +138,7 @@ function getQueryParameters(
136138interface DBSQLSessionConstructorOptions {
137139 handle : TSessionHandle ;
138140 context : IClientContext ;
141+ serverProtocolVersion ?: TProtocolVersion ;
139142}
140143
141144export default class DBSQLSession implements IDBSQLSession {
@@ -145,14 +148,22 @@ export default class DBSQLSession implements IDBSQLSession {
145148
146149 private isOpen = true ;
147150
151+ private serverProtocolVersion ?: TProtocolVersion ;
152+
148153 public onClose ?: ( ) => void ;
149154
150155 private operations = new CloseableCollection < DBSQLOperation > ( ) ;
151156
152- constructor ( { handle, context } : DBSQLSessionConstructorOptions ) {
157+ constructor ( { handle, context, serverProtocolVersion } : DBSQLSessionConstructorOptions ) {
153158 this . sessionHandle = handle ;
154159 this . context = context ;
160+ // Get the server protocol version from the provided parameter (from TOpenSessionResp)
161+ // rather than from the handle
162+ this . serverProtocolVersion = serverProtocolVersion ;
155163 this . context . getLogger ( ) . log ( LogLevel . debug , `Session created with id: ${ this . id } ` ) ;
164+ if ( this . serverProtocolVersion ) {
165+ this . context . getLogger ( ) . log ( LogLevel . debug , `Server protocol version: ${ this . serverProtocolVersion } ` ) ;
166+ }
156167 }
157168
158169 public get id ( ) {
@@ -193,17 +204,29 @@ export default class DBSQLSession implements IDBSQLSession {
193204 await this . failIfClosed ( ) ;
194205 const driver = await this . context . getDriver ( ) ;
195206 const clientConfig = this . context . getConfig ( ) ;
196- const operationPromise = driver . executeStatement ( {
207+
208+ const request = new TExecuteStatementReq ( {
197209 sessionHandle : this . sessionHandle ,
198210 statement,
199- queryTimeout : options . queryTimeout ? numberToInt64 ( options . queryTimeout ) : undefined ,
211+ queryTimeout : options . queryTimeout ? numberToInt64 ( options . queryTimeout ) : undefined ,
200212 runAsync : true ,
201213 ...getDirectResultsOptions ( options . maxRows , clientConfig ) ,
202- ...getArrowOptions ( clientConfig ) ,
203- canDownloadResult : options . useCloudFetch ?? clientConfig . useCloudFetch ,
204- parameters : getQueryParameters ( options . namedParameters , options . ordinalParameters ) ,
205- canDecompressLZ4Result : ( options . useLZ4Compression ?? clientConfig . useLZ4Compression ) && Boolean ( LZ4 ) ,
214+ ...getArrowOptions ( clientConfig , this . serverProtocolVersion ) ,
206215 } ) ;
216+
217+ if ( ProtocolVersion . supportsParameterizedQueries ( this . serverProtocolVersion ) ) {
218+ request . parameters = getQueryParameters ( options . namedParameters , options . ordinalParameters ) ;
219+ }
220+
221+ if ( ProtocolVersion . supportsArrowCompression ( this . serverProtocolVersion ) ) {
222+ request . canDecompressLZ4Result = ( options . useLZ4Compression ?? clientConfig . useLZ4Compression ) && Boolean ( LZ4 ) ;
223+ }
224+
225+ if ( ProtocolVersion . supportsCloudFetch ( this . serverProtocolVersion ) ) {
226+ request . canDownloadResult = options . useCloudFetch ?? clientConfig . useCloudFetch ;
227+ }
228+
229+ const operationPromise = driver . executeStatement ( request ) ;
207230 const response = await this . handleResponse ( operationPromise ) ;
208231 const operation = this . createOperation ( response ) ;
209232
@@ -352,9 +375,13 @@ export default class DBSQLSession implements IDBSQLSession {
352375 await this . failIfClosed ( ) ;
353376 const driver = await this . context . getDriver ( ) ;
354377 const clientConfig = this . context . getConfig ( ) ;
378+
379+ // Set runAsync only if supported by protocol version
380+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
381+
355382 const operationPromise = driver . getTypeInfo ( {
356383 sessionHandle : this . sessionHandle ,
357- runAsync : true ,
384+ runAsync,
358385 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
359386 } ) ;
360387 const response = await this . handleResponse ( operationPromise ) ;
@@ -371,9 +398,13 @@ export default class DBSQLSession implements IDBSQLSession {
371398 await this . failIfClosed ( ) ;
372399 const driver = await this . context . getDriver ( ) ;
373400 const clientConfig = this . context . getConfig ( ) ;
401+
402+ // Set runAsync only if supported by protocol version
403+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
404+
374405 const operationPromise = driver . getCatalogs ( {
375406 sessionHandle : this . sessionHandle ,
376- runAsync : true ,
407+ runAsync,
377408 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
378409 } ) ;
379410 const response = await this . handleResponse ( operationPromise ) ;
@@ -390,11 +421,15 @@ export default class DBSQLSession implements IDBSQLSession {
390421 await this . failIfClosed ( ) ;
391422 const driver = await this . context . getDriver ( ) ;
392423 const clientConfig = this . context . getConfig ( ) ;
424+
425+ // Set runAsync only if supported by protocol version
426+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
427+
393428 const operationPromise = driver . getSchemas ( {
394429 sessionHandle : this . sessionHandle ,
395430 catalogName : request . catalogName ,
396431 schemaName : request . schemaName ,
397- runAsync : true ,
432+ runAsync,
398433 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
399434 } ) ;
400435 const response = await this . handleResponse ( operationPromise ) ;
@@ -411,13 +446,17 @@ export default class DBSQLSession implements IDBSQLSession {
411446 await this . failIfClosed ( ) ;
412447 const driver = await this . context . getDriver ( ) ;
413448 const clientConfig = this . context . getConfig ( ) ;
449+
450+ // Set runAsync only if supported by protocol version
451+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
452+
414453 const operationPromise = driver . getTables ( {
415454 sessionHandle : this . sessionHandle ,
416455 catalogName : request . catalogName ,
417456 schemaName : request . schemaName ,
418457 tableName : request . tableName ,
419458 tableTypes : request . tableTypes ,
420- runAsync : true ,
459+ runAsync,
421460 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
422461 } ) ;
423462 const response = await this . handleResponse ( operationPromise ) ;
@@ -434,9 +473,13 @@ export default class DBSQLSession implements IDBSQLSession {
434473 await this . failIfClosed ( ) ;
435474 const driver = await this . context . getDriver ( ) ;
436475 const clientConfig = this . context . getConfig ( ) ;
476+
477+ // Set runAsync only if supported by protocol version
478+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
479+
437480 const operationPromise = driver . getTableTypes ( {
438481 sessionHandle : this . sessionHandle ,
439- runAsync : true ,
482+ runAsync,
440483 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
441484 } ) ;
442485 const response = await this . handleResponse ( operationPromise ) ;
@@ -453,13 +496,17 @@ export default class DBSQLSession implements IDBSQLSession {
453496 await this . failIfClosed ( ) ;
454497 const driver = await this . context . getDriver ( ) ;
455498 const clientConfig = this . context . getConfig ( ) ;
499+
500+ // Set runAsync only if supported by protocol version
501+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
502+
456503 const operationPromise = driver . getColumns ( {
457504 sessionHandle : this . sessionHandle ,
458505 catalogName : request . catalogName ,
459506 schemaName : request . schemaName ,
460507 tableName : request . tableName ,
461508 columnName : request . columnName ,
462- runAsync : true ,
509+ runAsync,
463510 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
464511 } ) ;
465512 const response = await this . handleResponse ( operationPromise ) ;
@@ -476,12 +523,16 @@ export default class DBSQLSession implements IDBSQLSession {
476523 await this . failIfClosed ( ) ;
477524 const driver = await this . context . getDriver ( ) ;
478525 const clientConfig = this . context . getConfig ( ) ;
526+
527+ // Set runAsync only if supported by protocol version
528+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
529+
479530 const operationPromise = driver . getFunctions ( {
480531 sessionHandle : this . sessionHandle ,
481532 catalogName : request . catalogName ,
482533 schemaName : request . schemaName ,
483534 functionName : request . functionName ,
484- runAsync : true ,
535+ runAsync,
485536 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
486537 } ) ;
487538 const response = await this . handleResponse ( operationPromise ) ;
@@ -492,12 +543,16 @@ export default class DBSQLSession implements IDBSQLSession {
492543 await this . failIfClosed ( ) ;
493544 const driver = await this . context . getDriver ( ) ;
494545 const clientConfig = this . context . getConfig ( ) ;
546+
547+ // Set runAsync only if supported by protocol version
548+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
549+
495550 const operationPromise = driver . getPrimaryKeys ( {
496551 sessionHandle : this . sessionHandle ,
497552 catalogName : request . catalogName ,
498553 schemaName : request . schemaName ,
499554 tableName : request . tableName ,
500- runAsync : true ,
555+ runAsync,
501556 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
502557 } ) ;
503558 const response = await this . handleResponse ( operationPromise ) ;
@@ -514,6 +569,10 @@ export default class DBSQLSession implements IDBSQLSession {
514569 await this . failIfClosed ( ) ;
515570 const driver = await this . context . getDriver ( ) ;
516571 const clientConfig = this . context . getConfig ( ) ;
572+
573+ // Set runAsync only if supported by protocol version
574+ const runAsync = ProtocolVersion . supportsAsyncMetadataOperations ( this . serverProtocolVersion ) ? true : undefined ;
575+
517576 const operationPromise = driver . getCrossReference ( {
518577 sessionHandle : this . sessionHandle ,
519578 parentCatalogName : request . parentCatalogName ,
@@ -522,7 +581,7 @@ export default class DBSQLSession implements IDBSQLSession {
522581 foreignCatalogName : request . foreignCatalogName ,
523582 foreignSchemaName : request . foreignSchemaName ,
524583 foreignTableName : request . foreignTableName ,
525- runAsync : true ,
584+ runAsync,
526585 ...getDirectResultsOptions ( request . maxRows , clientConfig ) ,
527586 } ) ;
528587 const response = await this . handleResponse ( operationPromise ) ;
0 commit comments