@@ -22,6 +22,7 @@ import {
2222 GetStatementResultCommand ,
2323 SqlParameter ,
2424} from '@aws-sdk/client-redshift-data' ;
25+ import { backOff } from 'exponential-backoff' ;
2526
2627export type RedshiftOptions = RedshiftDataClientConfig & Omit < ExecuteStatementCommandInput , "Sql" | "Parameters" > ;
2728
@@ -89,7 +90,6 @@ export class RedShiftDataSource extends DataSource<any, RedshiftOptions> {
8990 this . logger . debug (
9091 `Errors occurred, release connection from ${ profileName } `
9192 ) ;
92- redshiftClient . destroy ( ) ;
9393 throw e ;
9494 }
9595 }
@@ -114,7 +114,9 @@ export class RedShiftDataSource extends DataSource<any, RedshiftOptions> {
114114 const statementCommandResult = await redshiftClient . send ( executeStatementCommand ) ;
115115 return await this . getResultFromExecuteStatement ( statementCommandResult , redshiftClient ) ;
116116 } catch ( e ) {
117- redshiftClient . destroy ( ) ;
117+ this . logger . debug (
118+ `Errors occurred, release connection from ${ profileName } `
119+ ) ;
118120 throw e ;
119121 }
120122 }
@@ -132,7 +134,7 @@ export class RedShiftDataSource extends DataSource<any, RedshiftOptions> {
132134 // https://github.com/aws/aws-sdk-js-v3/blob/29056f4ca545f7e5cf951b915bb52178305fc305/clients/client-redshift-data/src/models/models_0.ts#L604
133135 while ( ! describeStatementResponse || describeStatementResponse . Status !== 'FINISHED' ) {
134136 const describeStatementCommand = new DescribeStatementCommand ( describeStatementRequestInput ) ;
135- describeStatementResponse = await redshiftClient . send ( describeStatementCommand ) ;
137+ describeStatementResponse = await backOff ( ( ) => redshiftClient . send ( describeStatementCommand ) ) ;
136138
137139 if (
138140 describeStatementResponse . Status === 'ABORTED' ||
@@ -142,15 +144,26 @@ export class RedShiftDataSource extends DataSource<any, RedshiftOptions> {
142144 }
143145 }
144146
145- const getStatementResultCommandParams : GetStatementResultCommandInput = {
147+ let getStatementResultCommandParams : GetStatementResultCommandInput = {
146148 "Id" : describeStatementResponse . Id
147149 } ;
148- const getStatementResultCommand = new GetStatementResultCommand ( getStatementResultCommandParams ) ;
149- const getStatementResultResponse = await redshiftClient . send ( getStatementResultCommand ) ;
150+ let getStatementResultCommand = new GetStatementResultCommand ( getStatementResultCommandParams ) ;
151+ let getStatementResultResponse = await redshiftClient . send ( getStatementResultCommand ) ;
152+ const records = getStatementResultResponse . Records ! || [ ] ;
153+ const columns = getStatementResultResponse . ColumnMetadata || [ ] ;
154+
155+ while ( getStatementResultResponse . NextToken ) {
156+ getStatementResultCommandParams = {
157+ "Id" : describeStatementResponse . Id ,
158+ "NextToken" : getStatementResultResponse . NextToken ,
159+ } ;
160+ getStatementResultCommand = new GetStatementResultCommand ( getStatementResultCommandParams ) ;
161+ getStatementResultResponse = await redshiftClient . send ( getStatementResultCommand ) ;
162+ records . push ( ...( getStatementResultResponse . Records ! || [ ] ) ) ;
163+ }
150164
151165 return {
152166 getColumns : ( ) => {
153- const columns = getStatementResultResponse . ColumnMetadata || [ ] ;
154167 return columns . map ( ( column ) => ( {
155168 name : column . name || '' ,
156169 type : mapFromRedShiftTypeId ( column . typeName ?. toLowerCase ( ) || '' ) ,
@@ -159,8 +172,6 @@ export class RedShiftDataSource extends DataSource<any, RedshiftOptions> {
159172 getData : ( ) => new Readable ( {
160173 objectMode : true ,
161174 read ( ) {
162- const records = getStatementResultResponse . Records ! || [ ] ;
163- const columns = getStatementResultResponse . ColumnMetadata || [ ] ;
164175 for ( const record of records ) {
165176 const row : RedShiftDataRow = { } ;
166177 for ( const [ i , recordField ] of record . entries ( ) ) {
0 commit comments