Skip to content

Commit 3bba803

Browse files
authored
fix(redshift-driver): fixes column order (#6068) Thanks @rdwoodring!
* fix(redshift-driver): fixes column order * fix(redshift-driver): resolves an issue with the original fix where types was not properly returned on success paths
1 parent ccbcc50 commit 3bba803

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/cubejs-redshift-driver/src/RedshiftDriver.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
152152
return false;
153153
}
154154

155-
public async unload(table: string, options: UnloadOptions): Promise<DownloadTableCSVData> {
155+
public async unload(tableName: string, options: UnloadOptions): Promise<DownloadTableCSVData> {
156156
if (!this.config.exportBucket) {
157157
throw new Error('Unload is not configured');
158158
}
159159

160+
const types = await this.tableColumnTypes(tableName);
161+
const columns = types.map(t => t.name).join(', ');
162+
160163
const { bucketType, bucketName, region, unloadArn, keyId, secretKey } = this.config.exportBucket;
161164

162165
const conn = await this.pool.connect();
@@ -198,7 +201,11 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
198201
}
199202
});
200203

201-
const baseQuery = `UNLOAD ('SELECT * FROM ${table}') TO '${bucketType}://${bucketName}/${exportPathName}/'`;
204+
const baseQuery = `
205+
UNLOAD ('SELECT ${columns} FROM ${tableName}')
206+
TO '${bucketType}://${bucketName}/${exportPathName}/'
207+
`;
208+
202209
// Prefer the unloadArn if it is present
203210
const credentialQuery = unloadArn
204211
? `iam_role '${unloadArn}'`
@@ -215,6 +222,7 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
215222
return {
216223
exportBucketCsvEscapeSymbol: this.config.exportBucketCsvEscapeSymbol,
217224
csvFile: [],
225+
types
218226
};
219227
}
220228

@@ -243,6 +251,7 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
243251
return {
244252
exportBucketCsvEscapeSymbol: this.config.exportBucketCsvEscapeSymbol,
245253
csvFile,
254+
types
246255
};
247256
}
248257

0 commit comments

Comments
 (0)