Skip to content

Commit 8e15482

Browse files
lawofcyclesvinayak-kukrejasumupitchayan
authored
feat(glue-alpha): add cfn-glue-table-tableinput-parameters to Glue table construct (#27643)
Add [cfn-glue-table-tableinput-parameters](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-tableinput.html#cfn-glue-table-tableinput-parameters) to Glue Table construct as optional props User can specify additional table parameter when creating Glue Table. Any key/value can be set depending on each user's requirement like table's additional metadata or statistics. Some parameter can be used when AWS services / 3rd party tools read table like `skip.header.line.count`. Closes #14159. --- All Submissions: - [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) Adding new Unconventional Dependencies: - [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) New Features - [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? - [x] Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)? --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Co-authored-by: Vinayak Kukreja <[email protected]> Co-authored-by: Sumu Pitchayan <[email protected]>
1 parent 832e29a commit 8e15482

12 files changed

+309
-21
lines changed

packages/@aws-cdk/aws-glue-alpha/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ new glue.S3Table(this, 'MyTable', {
263263
});
264264
```
265265

266+
Glue tables can also be configured to contain user-defined table properties through the [`parameters`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-tableinput.html#cfn-glue-table-tableinput-parameters) property:
267+
268+
```ts
269+
declare const myDatabase: glue.Database;
270+
new glue.S3Table(this, 'MyTable', {
271+
parameters: {
272+
key1: 'val1',
273+
key2: 'val2',
274+
},
275+
database: myDatabase,
276+
columns: [{
277+
name: 'col1',
278+
type: glue.Schema.STRING,
279+
}],
280+
dataFormat: glue.DataFormat.JSON,
281+
});
282+
```
283+
266284
### Partition Keys
267285

268286
To improve query performance, a table can specify `partitionKeys` on which data is stored and queried separately. For example, you might partition a table by `year` and `month` to optimize queries based on a time window:

packages/@aws-cdk/aws-glue-alpha/lib/external-table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class ExternalTable extends TableBase {
6969
'has_encrypted_data': true,
7070
'partition_filtering.enabled': props.enablePartitionFiltering,
7171
'connectionName': props.connection.connectionName,
72+
...props.parameters,
7273
},
7374
storageDescriptor: {
7475
location: props.externalDataLocation,

packages/@aws-cdk/aws-glue-alpha/lib/s3-table.ts

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export class S3Table extends TableBase {
141141
'classification': props.dataFormat.classificationString?.value,
142142
'has_encrypted_data': true,
143143
'partition_filtering.enabled': props.enablePartitionFiltering,
144+
...this.parameters,
144145
},
145146
storageDescriptor: {
146147
location: `s3://${this.bucket.bucketName}/${this.s3Prefix}`,

packages/@aws-cdk/aws-glue-alpha/lib/table-base.ts

+17
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ export interface TableBaseProps {
147147
* @default - The parameter is not defined
148148
*/
149149
readonly storageParameters?: StorageParameter[];
150+
151+
/**
152+
* The key/value pairs define properties associated with the table.
153+
* The key/value pairs that are allowed to be submitted are not limited, however their functionality is not guaranteed.
154+
*
155+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-tableinput.html#cfn-glue-table-tableinput-parameters
156+
*
157+
* @default - The parameter is not defined
158+
*/
159+
readonly parameters?: { [key: string]: string }
150160
}
151161

152162
/**
@@ -214,6 +224,12 @@ export abstract class TableBase extends Resource implements ITable {
214224
*/
215225
public readonly storageParameters?: StorageParameter[];
216226

227+
/**
228+
* The tables' properties associated with the table.
229+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-tableinput.html#cfn-glue-table-tableinput-parameters
230+
*/
231+
protected readonly parameters: { [key: string]: string }
232+
217233
/**
218234
* Partition indexes must be created one at a time. To avoid
219235
* race conditions, we store the resource and add dependencies
@@ -236,6 +252,7 @@ export abstract class TableBase extends Resource implements ITable {
236252
this.columns = props.columns;
237253
this.partitionKeys = props.partitionKeys;
238254
this.storageParameters = props.storageParameters;
255+
this.parameters = props.parameters ?? {};
239256

240257
this.compressed = props.compressed ?? false;
241258
}

packages/@aws-cdk/aws-glue-alpha/test/external-table.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,47 @@ test('can associate an external location with the glue table', () => {
10661066
});
10671067
});
10681068

1069+
test('can specify table parameter', () => {
1070+
const app = new cdk.App();
1071+
const stack = new cdk.Stack(app, 'Stack');
1072+
const database = new glue.Database(stack, 'Database');
1073+
const connection = new glue.Connection(stack, 'Connection', {
1074+
connectionName: 'my_connection',
1075+
type: glue.ConnectionType.JDBC,
1076+
properties: {
1077+
JDBC_CONNECTION_URL: 'jdbc:server://server:443/connection',
1078+
USERNAME: 'username',
1079+
PASSWORD: 'password',
1080+
},
1081+
});
1082+
new glue.ExternalTable(stack, 'Table', {
1083+
database,
1084+
tableName: 'my_table',
1085+
connection,
1086+
columns: [{
1087+
name: 'col',
1088+
type: glue.Schema.STRING,
1089+
}],
1090+
dataFormat: glue.DataFormat.JSON,
1091+
externalDataLocation,
1092+
parameters: {
1093+
key1: 'val1',
1094+
key2: 'val2',
1095+
},
1096+
});
1097+
1098+
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Table', {
1099+
TableInput: {
1100+
Parameters: {
1101+
key1: 'val1',
1102+
key2: 'val2',
1103+
classification: 'json',
1104+
has_encrypted_data: true,
1105+
},
1106+
},
1107+
});
1108+
});
1109+
10691110
function createTable(props: Pick<glue.S3TableProps, Exclude<keyof glue.S3TableProps, 'database' | 'dataFormat'>>): void {
10701111
const stack = new cdk.Stack();
10711112
const connection = new glue.Connection(stack, 'Connection', {

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.assets.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/aws-cdk-glue.template.json

+66
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,72 @@
623623
}
624624
}
625625
},
626+
"MyTableWithParametersTable39568AB8": {
627+
"Type": "AWS::Glue::Table",
628+
"Properties": {
629+
"CatalogId": {
630+
"Ref": "AWS::AccountId"
631+
},
632+
"DatabaseName": {
633+
"Ref": "MyDatabase1E2517DB"
634+
},
635+
"TableInput": {
636+
"Description": "table_with_parameters generated by CDK",
637+
"Name": "table_with_parameters",
638+
"Parameters": {
639+
"classification": "json",
640+
"has_encrypted_data": true,
641+
"key1": "val1",
642+
"key2": "val2"
643+
},
644+
"StorageDescriptor": {
645+
"Columns": [
646+
{
647+
"Name": "col1",
648+
"Type": "string"
649+
},
650+
{
651+
"Comment": "col2 comment",
652+
"Name": "col2",
653+
"Type": "string"
654+
},
655+
{
656+
"Name": "col3",
657+
"Type": "array<string>"
658+
},
659+
{
660+
"Name": "col4",
661+
"Type": "map<string,string>"
662+
},
663+
{
664+
"Name": "col5",
665+
"Type": "struct<col1:string>"
666+
}
667+
],
668+
"Compressed": false,
669+
"InputFormat": "org.apache.hadoop.mapred.TextInputFormat",
670+
"Location": {
671+
"Fn::Join": [
672+
"",
673+
[
674+
"s3://",
675+
{
676+
"Ref": "DataBucketE3889A50"
677+
},
678+
"/"
679+
]
680+
]
681+
},
682+
"OutputFormat": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
683+
"SerdeInfo": {
684+
"SerializationLibrary": "org.openx.data.jsonserde.JsonSerDe"
685+
},
686+
"StoredAsSubDirectories": false
687+
},
688+
"TableType": "EXTERNAL_TABLE"
689+
}
690+
}
691+
},
626692
"MyDeprecatedTableAA0364FD": {
627693
"Type": "AWS::Glue::Table",
628694
"Properties": {

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/manifest.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.js.snapshot/tree.json

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

packages/@aws-cdk/aws-glue-alpha/test/integ.table.ts

+12
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ new glue.S3Table(stack, 'MyTableWithStorageDescriptorParameters', {
124124
],
125125
});
126126

127+
new glue.S3Table(stack, 'MyTableWithParameters', {
128+
database,
129+
bucket,
130+
tableName: 'table_with_parameters',
131+
columns,
132+
dataFormat: glue.DataFormat.JSON,
133+
parameters: {
134+
key1: 'val1',
135+
key2: 'val2',
136+
},
137+
});
138+
127139
new glue.Table(stack, 'MyDeprecatedTable', {
128140
database,
129141
bucket,

0 commit comments

Comments
 (0)