Skip to content

Commit

Permalink
fix(glue): empty string in Table.s3prefix is not undefined (#5783)
Browse files Browse the repository at this point in the history
When the Glue Table's s3Prefix property is an empty string,
it should not be replaced with the default value.

Fixes #5763
  • Loading branch information
melgenek authored and skinny85 committed Jan 13, 2020
1 parent 5292bd5 commit 18e15de
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-glue/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class Table extends Resource implements ITable {

this.database = props.database;
this.dataFormat = props.dataFormat;
this.s3Prefix = props.s3Prefix || 'data/';
this.s3Prefix = (props.s3Prefix !== undefined && props.s3Prefix !== null) ? props.s3Prefix : 'data/';

validateSchema(props.columns, props.partitionKeys);
this.columns = props.columns;
Expand Down
68 changes: 68 additions & 0 deletions packages/@aws-cdk/aws-glue/test/test.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,74 @@ export = {
test.done();
},

'explicit s3 bucket and with empty prefix'(test: Test) {
const app = new cdk.App();
const dbStack = new cdk.Stack(app, 'db');
const stack = new cdk.Stack(app, 'app');
const bucket = new s3.Bucket(stack, 'ExplicitBucket');
const database = new glue.Database(dbStack, 'Database', {
databaseName: 'database',
});

new glue.Table(stack, 'Table', {
database,
bucket,
s3Prefix: '',
tableName: 'table',
columns: [{
name: 'col',
type: glue.Schema.STRING
}],
dataFormat: glue.DataFormat.Json,
});

expect(stack).to(haveResource('AWS::Glue::Table', {
CatalogId: {
Ref: "AWS::AccountId"
},
DatabaseName: {
"Fn::ImportValue": "db:ExportsOutputRefDatabaseB269D8BB88F4B1C4"
},
TableInput: {
Description: "table generated by CDK",
Name: "table",
Parameters: {
has_encrypted_data: false
},
StorageDescriptor: {
Columns: [
{
Name: "col",
Type: "string"
}
],
Compressed: false,
InputFormat: "org.apache.hadoop.mapred.TextInputFormat",
Location: {
"Fn::Join": [
"",
[
"s3://",
{
Ref: "ExplicitBucket0AA51A3F"
},
"/"
]
]
},
OutputFormat: "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
SerdeInfo: {
SerializationLibrary: "org.openx.data.jsonserde.JsonSerDe"
},
StoredAsSubDirectories: false
},
TableType: "EXTERNAL_TABLE"
}
}));

test.done();
},

'grants': {
'read only'(test: Test) {
const stack = new cdk.Stack();
Expand Down

0 comments on commit 18e15de

Please sign in to comment.