Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(redshift): Column ids were not being default assigned #24546

Merged
merged 13 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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