Skip to content

Commit

Permalink
feat(glue): database description property (aws#27744)
Browse files Browse the repository at this point in the history
Closes aws#27740.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
msambol authored and paulhcsun committed Jan 5, 2024
1 parent 366a946 commit bdc1c26
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ See [documentation](https://docs.aws.amazon.com/glue/latest/dg/encryption-securi
A `Database` is a logical grouping of `Tables` in the Glue Catalog.

```ts
new glue.Database(this, 'MyDatabase');
new glue.Database(this, 'MyDatabase', {
databaseName: 'my_database',
description: 'my_database_description',
});
```

## Table
Expand Down
20 changes: 19 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/lib/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export interface DatabaseProps {
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-database-databaseinput.html
*/
readonly locationUri?: string;

/**
* A description of the database.
*
* @default - no database description
*/
readonly description?: string;
}

/**
Expand Down Expand Up @@ -96,8 +103,13 @@ export class Database extends Resource implements IDatabase {
}),
});

if (props.description !== undefined) {
validateDescription(props.description);
}

let databaseInput: CfnDatabase.DatabaseInputProperty = {
name: this.physicalName,
description: props.description,
};

if (props.locationUri !== undefined) {
Expand Down Expand Up @@ -133,6 +145,12 @@ export class Database extends Resource implements IDatabase {

function validateLocationUri(locationUri: string): void {
if (locationUri.length < 1 || locationUri.length > 1024) {
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, but was ${locationUri.length}`);
throw new Error(`locationUri length must be (inclusively) between 1 and 1024, got ${locationUri.length}`);
}
}

function validateDescription(description: string): void {
if (description.length > 2048) {
throw new Error(`description length must be less than or equal to 2048, got ${description.length}`);
}
}
33 changes: 32 additions & 1 deletion packages/@aws-cdk/aws-glue-alpha/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ test('explicit locationURI', () => {

});

test('explicit description', () => {
new glue.Database(stack, 'Database', {
description: 'database-description',
});

Template.fromStack(stack).templateMatches({
Resources: {
DatabaseB269D8BB: {
Type: 'AWS::Glue::Database',
Properties: {
CatalogId: {
Ref: 'AWS::AccountId',
},
DatabaseInput: {
Description: 'database-description',
Name: 'database',
},
},
},
},
});
});

test('fromDatabase', () => {
// WHEN
const database = glue.Database.fromDatabaseArn(stack, 'import', 'arn:aws:glue:us-east-1:123456789012:database/db1');
Expand Down Expand Up @@ -85,7 +108,15 @@ test('locationUri length must be <= 1024', () => {
new glue.Database(stack, 'Database', {
locationUri: 'a'.repeat(1025),
}),
).toThrow();
).toThrow('locationUri length must be (inclusively) between 1 and 1024, got 1025');
});

test('description length must be <= 2048', () => {
expect(() =>
new glue.Database(stack, 'Database', {
description: 'a'.repeat(2049),
}),
).toThrow('description length must be less than or equal to 2048, got 2049');
});

test('can specify a physical name', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"Ref": "AWS::AccountId"
},
"DatabaseInput": {
"Description": "my_database_description",
"Name": "my_database"
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const bucket = new s3.Bucket(stack, 'DataBucket', {

const database = new glue.Database(stack, 'MyDatabase', {
databaseName: 'my_database',
description: 'my_database_description',
});

const columns = [{
Expand Down

0 comments on commit bdc1c26

Please sign in to comment.