Skip to content

Commit

Permalink
Merge branch 'main' into gh-24654
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 12, 2023
2 parents 309eda1 + 8a655bd commit 5fa2f09
Show file tree
Hide file tree
Showing 29 changed files with 1,464 additions and 1,856 deletions.
16 changes: 12 additions & 4 deletions packages/@aws-cdk/aws-redshift/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export class Table extends TableBase {
constructor(scope: Construct, id: string, props: TableProps) {
super(scope, id);

this.addColumnIds(props.tableColumns);
this.validateDistKeyColumns(props.tableColumns);
if (props.distStyle) {
this.validateDistStyle(props.distStyle, props.tableColumns);
Expand All @@ -251,7 +250,7 @@ export class Table extends TableBase {
this.validateSortStyle(props.sortStyle, props.tableColumns);
}

this.tableColumns = props.tableColumns;
this.tableColumns = this.configureTableColumns(props.tableColumns);
this.cluster = props.cluster;
this.databaseName = props.databaseName;

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

private addColumnIds(columns: Column[]): void {
private configureTableColumns(columns: Column[]): Column[] {
const newColumns = [...columns];
const columnIds = new Set<string>();
for (const column of columns) {
for (let i = 0; i < columns.length; i++) {
const column = newColumns[i];
if (column.id) {
if (columnIds.has(column.id)) {
throw new Error(`Column id '${column.id}' is not unique.`);
}
columnIds.add(column.id);
} else {
if (columnIds.has(column.name)) {
throw new Error(`Column name '${column.name}' is not unique amongst the column ids.`);
}
newColumns[i] = { ...column, id: column.name };
columnIds.add(column.name);
}
}
return newColumns;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ new redshift.Table(stack, 'Table', {
tableColumns: [
{ id: 'col1', name: 'col1', dataType: 'varchar(4)' },
{ id: 'col2', name: 'col2', dataType: 'float' },
{ id: 'col3', name: 'col3', dataType: 'float' },
{ name: 'col3', dataType: 'float' },
],
});

Expand Down

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5fa2f09

Please sign in to comment.