Skip to content

Commit 8a655bd

Browse files
authored
fix(redshift): Column ids were not being default assigned (#24546)
The side effect to add the column ids, if not present, was not being performed. This functionality was supposed to be added, but was overlooked. Closes #24545. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0480e47 commit 8a655bd

File tree

27 files changed

+1447
-1855
lines changed

27 files changed

+1447
-1855
lines changed

packages/@aws-cdk/aws-redshift/lib/table.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ export class Table extends TableBase {
242242
constructor(scope: Construct, id: string, props: TableProps) {
243243
super(scope, id);
244244

245-
this.addColumnIds(props.tableColumns);
246245
this.validateDistKeyColumns(props.tableColumns);
247246
if (props.distStyle) {
248247
this.validateDistStyle(props.distStyle, props.tableColumns);
@@ -251,7 +250,7 @@ export class Table extends TableBase {
251250
this.validateSortStyle(props.sortStyle, props.tableColumns);
252251
}
253252

254-
this.tableColumns = props.tableColumns;
253+
this.tableColumns = this.configureTableColumns(props.tableColumns);
255254
this.cluster = props.cluster;
256255
this.databaseName = props.databaseName;
257256

@@ -327,16 +326,25 @@ export class Table extends TableBase {
327326
return (sortKeyColumns.length === 0) ? TableSortStyle.AUTO : TableSortStyle.COMPOUND;
328327
}
329328

330-
private addColumnIds(columns: Column[]): void {
329+
private configureTableColumns(columns: Column[]): Column[] {
330+
const newColumns = [...columns];
331331
const columnIds = new Set<string>();
332-
for (const column of columns) {
332+
for (let i = 0; i < columns.length; i++) {
333+
const column = newColumns[i];
333334
if (column.id) {
334335
if (columnIds.has(column.id)) {
335336
throw new Error(`Column id '${column.id}' is not unique.`);
336337
}
337338
columnIds.add(column.id);
339+
} else {
340+
if (columnIds.has(column.name)) {
341+
throw new Error(`Column name '${column.name}' is not unique amongst the column ids.`);
342+
}
343+
newColumns[i] = { ...column, id: column.name };
344+
columnIds.add(column.name);
338345
}
339346
}
347+
return newColumns;
340348
}
341349
}
342350

packages/@aws-cdk/aws-redshift/test/integ.database-columnid.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ new redshift.Table(stack, 'Table', {
4848
tableColumns: [
4949
{ id: 'col1', name: 'col1', dataType: 'varchar(4)' },
5050
{ id: 'col2', name: 'col2', dataType: 'float' },
51-
{ id: 'col3', name: 'col3', dataType: 'float' },
51+
{ name: 'col3', dataType: 'float' },
5252
],
5353
});
5454

packages/@aws-cdk/aws-redshift/test/integ.database.js.snapshot/asset.169a8c0beb97c903ee155ea9653e39b0884c9e3b860ac72ffbe906b3c1f4e338/table.js

-148
This file was deleted.

packages/@aws-cdk/aws-redshift/test/integ.database.js.snapshot/asset.1a159599b617b432864ddf9e4e9ec70b884de7656daa51073d4149a3080c5f79/table.js

+171
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-redshift/test/integ.database.js.snapshot/asset.847e15feeb180b356ab9a8094d8b9459ea8ec26fc27957794d583ed9eb3a79d8/handler-name.js

-10
This file was deleted.

packages/@aws-cdk/aws-redshift/test/integ.database.js.snapshot/asset.847e15feeb180b356ab9a8094d8b9459ea8ec26fc27957794d583ed9eb3a79d8/index.js

-23
This file was deleted.

packages/@aws-cdk/aws-redshift/test/integ.database.js.snapshot/asset.847e15feeb180b356ab9a8094d8b9459ea8ec26fc27957794d583ed9eb3a79d8/privileges.js

-58
This file was deleted.

0 commit comments

Comments
 (0)