Skip to content

Commit

Permalink
fix(redshift-driver): Fix empty tableColumnTypes for external (Spectr…
Browse files Browse the repository at this point in the history
…um) tables (#9251)
  • Loading branch information
KSDaemon authored Feb 24, 2025
1 parent ccc33b8 commit fa318a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/cubejs-redshift-driver/src/RedshiftDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
StreamOptions,
StreamTableDataWithTypes,
TableColumn,
TableStructure,
UnloadOptions
} from '@cubejs-backend/base-driver';
import crypto from 'crypto';
Expand Down Expand Up @@ -341,6 +342,19 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
// @todo Implement for Redshift, column \"typcategory\" does not exist in pg_type
}

public override async tableColumnTypes(table: string): Promise<TableStructure> {
const [schema, name] = table.split('.');

// We might get table from Spectrum schema, so common request via `information_schema.columns`
// won't return anything. `getColumnsForSpecificTables` is aware of Spectrum tables.
const columns = await this.getColumnsForSpecificTables([{
schema_name: schema,
table_name: name,
}]);

return columns.map(c => ({ name: c.column_name, type: this.toGenericType(c.data_type) }));
}

public async isUnloadSupported() {
if (this.config.exportBucket) {
return true;
Expand Down
12 changes: 12 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testExternalSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@ export function redshiftExternalSchemasSuite(
expect(it.data_type).toEqual(expect.any(String));
});
});

execute('should load columns types for external table', async () => {
const columnsForTables = await driver().tableColumnTypes(`${EXTERNAL_SCHEMA}.${EXTERNAL_TABLE}`);

expect(columnsForTables).toBeInstanceOf(Array);
expect(columnsForTables.length).toBeGreaterThan(0);

columnsForTables.forEach((it) => {
expect(it.name).toEqual(expect.any(String));
expect(it.type).toEqual(expect.any(String));
});
});
}

0 comments on commit fa318a1

Please sign in to comment.