Skip to content

Commit fa318a1

Browse files
authored
fix(redshift-driver): Fix empty tableColumnTypes for external (Spectrum) tables (#9251)
1 parent ccc33b8 commit fa318a1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
StreamOptions,
1717
StreamTableDataWithTypes,
1818
TableColumn,
19+
TableStructure,
1920
UnloadOptions
2021
} from '@cubejs-backend/base-driver';
2122
import crypto from 'crypto';
@@ -341,6 +342,19 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
341342
// @todo Implement for Redshift, column \"typcategory\" does not exist in pg_type
342343
}
343344

345+
public override async tableColumnTypes(table: string): Promise<TableStructure> {
346+
const [schema, name] = table.split('.');
347+
348+
// We might get table from Spectrum schema, so common request via `information_schema.columns`
349+
// won't return anything. `getColumnsForSpecificTables` is aware of Spectrum tables.
350+
const columns = await this.getColumnsForSpecificTables([{
351+
schema_name: schema,
352+
table_name: name,
353+
}]);
354+
355+
return columns.map(c => ({ name: c.column_name, type: this.toGenericType(c.data_type) }));
356+
}
357+
344358
public async isUnloadSupported() {
345359
if (this.config.exportBucket) {
346360
return true;

packages/cubejs-testing-drivers/src/tests/testExternalSchemas.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ export function redshiftExternalSchemasSuite(
4646
expect(it.data_type).toEqual(expect.any(String));
4747
});
4848
});
49+
50+
execute('should load columns types for external table', async () => {
51+
const columnsForTables = await driver().tableColumnTypes(`${EXTERNAL_SCHEMA}.${EXTERNAL_TABLE}`);
52+
53+
expect(columnsForTables).toBeInstanceOf(Array);
54+
expect(columnsForTables.length).toBeGreaterThan(0);
55+
56+
columnsForTables.forEach((it) => {
57+
expect(it.name).toEqual(expect.any(String));
58+
expect(it.type).toEqual(expect.any(String));
59+
});
60+
});
4961
}

0 commit comments

Comments
 (0)