@@ -23,6 +23,7 @@ import RowSetProvider from '../result/RowSetProvider';
2323import JsonResultHandler from '../result/JsonResultHandler' ;
2424import ArrowResultHandler from '../result/ArrowResultHandler' ;
2525import CloudFetchResultHandler from '../result/CloudFetchResultHandler' ;
26+ import ResultSlicer from '../result/ResultSlicer' ;
2627import { definedOrError } from '../utils' ;
2728import HiveDriverError from '../errors/HiveDriverError' ;
2829import IClientContext from '../contracts/IClientContext' ;
@@ -68,7 +69,7 @@ export default class DBSQLOperation implements IOperation {
6869
6970 private hasResultSet : boolean = false ;
7071
71- private resultHandler ?: IResultsProvider < Array < any > > ;
72+ private resultHandler ?: ResultSlicer < any > ;
7273
7374 constructor ( { handle, directResults, context } : DBSQLOperationConstructorOptions ) {
7475 this . operationHandle = handle ;
@@ -107,9 +108,17 @@ export default class DBSQLOperation implements IOperation {
107108 */
108109 public async fetchAll ( options ?: FetchOptions ) : Promise < Array < object > > {
109110 const data : Array < Array < object > > = [ ] ;
111+
112+ const fetchChunkOptions = {
113+ ...options ,
114+ // Tell slicer to return raw chunks. We're going to process all of them anyway,
115+ // so no need to additionally buffer and slice chunks returned by server
116+ disableBuffering : true ,
117+ } ;
118+
110119 do {
111120 // eslint-disable-next-line no-await-in-loop
112- const chunk = await this . fetchChunk ( options ) ;
121+ const chunk = await this . fetchChunk ( fetchChunkOptions ) ;
113122 data . push ( chunk ) ;
114123 } while ( await this . hasMoreRows ( ) ) ; // eslint-disable-line no-await-in-loop
115124 this . context . getLogger ( ) . log ( LogLevel . debug , `Fetched all data from operation with id: ${ this . getId ( ) } ` ) ;
@@ -138,7 +147,10 @@ export default class DBSQLOperation implements IOperation {
138147 const resultHandler = await this . getResultHandler ( ) ;
139148 await this . failIfClosed ( ) ;
140149
141- const result = resultHandler . fetchNext ( { limit : options ?. maxRows || defaultMaxRows } ) ;
150+ const result = resultHandler . fetchNext ( {
151+ limit : options ?. maxRows || defaultMaxRows ,
152+ disableBuffering : options ?. disableBuffering ,
153+ } ) ;
142154 await this . failIfClosed ( ) ;
143155
144156 this . context
@@ -335,24 +347,28 @@ export default class DBSQLOperation implements IOperation {
335347 return this . metadata ;
336348 }
337349
338- private async getResultHandler ( ) : Promise < IResultsProvider < Array < any > > > {
350+ private async getResultHandler ( ) : Promise < ResultSlicer < any > > {
339351 const metadata = await this . fetchMetadata ( ) ;
340352 const resultFormat = definedOrError ( metadata . resultFormat ) ;
341353
342354 if ( ! this . resultHandler ) {
355+ let resultSource : IResultsProvider < Array < any > > | undefined ;
356+
343357 switch ( resultFormat ) {
344358 case TSparkRowSetType . COLUMN_BASED_SET :
345- this . resultHandler = new JsonResultHandler ( this . context , this . _data , metadata . schema ) ;
359+ resultSource = new JsonResultHandler ( this . context , this . _data , metadata . schema ) ;
346360 break ;
347361 case TSparkRowSetType . ARROW_BASED_SET :
348- this . resultHandler = new ArrowResultHandler ( this . context , this . _data , metadata . schema , metadata . arrowSchema ) ;
362+ resultSource = new ArrowResultHandler ( this . context , this . _data , metadata . schema , metadata . arrowSchema ) ;
349363 break ;
350364 case TSparkRowSetType . URL_BASED_SET :
351- this . resultHandler = new CloudFetchResultHandler ( this . context , this . _data , metadata . schema ) ;
352- break ;
353- default :
354- this . resultHandler = undefined ;
365+ resultSource = new CloudFetchResultHandler ( this . context , this . _data , metadata . schema ) ;
355366 break ;
367+ // no default
368+ }
369+
370+ if ( resultSource ) {
371+ this . resultHandler = new ResultSlicer ( this . context , resultSource ) ;
356372 }
357373 }
358374
0 commit comments