@@ -4,6 +4,7 @@ import Status from '../dto/Status';
44import IOperationResult from '../result/IOperationResult' ;
55import JsonResult from '../result/JsonResult' ;
66import ArrowResult from '../result/ArrowResult' ;
7+ import CloudFetchResult from '../result/CloudFetchResult' ;
78import HiveDriverError from '../errors/HiveDriverError' ;
89import { definedOrError } from '../utils' ;
910
@@ -14,6 +15,8 @@ export default class SchemaHelper {
1415
1516 private metadata ?: TGetResultSetMetadataResp ;
1617
18+ private resultHandler ?: IOperationResult ;
19+
1720 constructor ( driver : HiveDriver , operationHandle : TOperationHandle , metadata ?: TGetResultSetMetadataResp ) {
1821 this . driver = driver ;
1922 this . operationHandle = operationHandle ;
@@ -41,13 +44,27 @@ export default class SchemaHelper {
4144 const metadata = await this . fetchMetadata ( ) ;
4245 const resultFormat = definedOrError ( metadata . resultFormat ) ;
4346
44- switch ( resultFormat ) {
45- case TSparkRowSetType . COLUMN_BASED_SET :
46- return new JsonResult ( metadata . schema ) ;
47- case TSparkRowSetType . ARROW_BASED_SET :
48- return new ArrowResult ( metadata . schema , metadata . arrowSchema ) ;
49- default :
50- throw new HiveDriverError ( `Unsupported result format: ${ TSparkRowSetType [ resultFormat ] } ` ) ;
47+ if ( ! this . resultHandler ) {
48+ switch ( resultFormat ) {
49+ case TSparkRowSetType . COLUMN_BASED_SET :
50+ this . resultHandler = new JsonResult ( metadata . schema ) ;
51+ break ;
52+ case TSparkRowSetType . ARROW_BASED_SET :
53+ this . resultHandler = new ArrowResult ( metadata . schema , metadata . arrowSchema ) ;
54+ break ;
55+ case TSparkRowSetType . URL_BASED_SET :
56+ this . resultHandler = new CloudFetchResult ( metadata . schema ) ;
57+ break ;
58+ default :
59+ this . resultHandler = undefined ;
60+ break ;
61+ }
62+ }
63+
64+ if ( ! this . resultHandler ) {
65+ throw new HiveDriverError ( `Unsupported result format: ${ TSparkRowSetType [ resultFormat ] } ` ) ;
5166 }
67+
68+ return this . resultHandler ;
5269 }
5370}
0 commit comments