Skip to content

Commit af3a188

Browse files
authored
feat(glue): support Data Quality ruleset (#26272)
Glue launched Glue Data Quality. https://aws.amazon.com/about-aws/whats-new/2023/06/aws-glue-data-quality-generally-available/ This PR is to support the Glue Data Quality in AWS CDK. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d34e7c9 commit af3a188

14 files changed

+925
-2
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,23 @@ new glue.Table(this, 'MyTable', {
493493
| array(itemType: Type) | Function | An array of some other type |
494494
| map(keyType: Type, valueType: Type) | Function | A map of some primitive key type to any value type |
495495
| struct(collumns: Column[]) | Function | Nested structure containing individually named and typed collumns |
496+
497+
## Data Quality Ruleset
498+
499+
A `DataQualityRuleset` specifies a data quality ruleset with DQDL rules applied to a specified AWS Glue table. For example, to create a data quality ruleset for a given table:
500+
501+
```ts
502+
new glue.DataQualityRuleset(this, 'MyDataQualityRuleset', {
503+
clientToken: 'client_token',
504+
description: 'description',
505+
rulesetName: 'ruleset_name',
506+
rulesetDqdl: 'ruleset_dqdl',
507+
tags: {
508+
key1: 'value1',
509+
key2: 'value2',
510+
},
511+
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'),
512+
});
513+
```
514+
515+
For more information, see [AWS Glue Data Quality](https://docs.aws.amazon.com/glue/latest/dg/glue-data-quality.html).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as constructs from 'constructs';
3+
import { IResource, Resource } from 'aws-cdk-lib/core';
4+
import { CfnDataQualityRuleset } from 'aws-cdk-lib/aws-glue';
5+
6+
/**
7+
* Properties of a DataQualityTargetTable.
8+
*/
9+
export class DataQualityTargetTable {
10+
/**
11+
* The database name of the target table.
12+
*/
13+
readonly databaseName: string;
14+
15+
/**
16+
* The table name of the target table.
17+
*/
18+
readonly tableName: string;
19+
20+
constructor(databaseName: string, tableName: string) {
21+
this.databaseName = databaseName;
22+
this.tableName = tableName;
23+
}
24+
}
25+
26+
export interface IDataQualityRuleset extends IResource {
27+
/**
28+
* The ARN of the ruleset
29+
* @attribute
30+
*/
31+
readonly rulesetArn: string;
32+
33+
/**
34+
* The name of the ruleset
35+
* @attribute
36+
*/
37+
readonly rulesetName: string;
38+
}
39+
40+
/**
41+
* Construction properties for `DataQualityRuleset`
42+
*/
43+
export interface DataQualityRulesetProps {
44+
/**
45+
* The name of the ruleset
46+
* @default cloudformation generated name
47+
*/
48+
readonly rulesetName?: string;
49+
50+
/**
51+
* The client token of the ruleset
52+
* @attribute
53+
*/
54+
readonly clientToken?: string;
55+
56+
/**
57+
* The description of the ruleset
58+
* @attribute
59+
*/
60+
readonly description?: string;
61+
62+
/**
63+
* The dqdl of the ruleset
64+
* @attribute
65+
*/
66+
readonly rulesetDqdl: string;
67+
68+
/**
69+
* Key-Value pairs that define tags for the ruleset.
70+
* @default empty tags
71+
*/
72+
readonly tags?: { [key: string]: string };
73+
74+
/**
75+
* The target table of the ruleset
76+
* @attribute
77+
*/
78+
readonly targetTable: DataQualityTargetTable;
79+
}
80+
81+
/**
82+
* A Glue Data Quality ruleset.
83+
*/
84+
export class DataQualityRuleset extends Resource implements IDataQualityRuleset {
85+
public static fromRulesetArn(scope: constructs.Construct, id: string, rulesetArn: string): IDataQualityRuleset {
86+
class Import extends Resource implements IDataQualityRuleset {
87+
public rulesetArn = rulesetArn;
88+
public rulesetName = cdk.Arn.extractResourceName(rulesetArn, 'dataqualityruleset');
89+
}
90+
91+
return new Import(scope, id);
92+
}
93+
94+
public static fromRulesetName(scope: constructs.Construct, id: string, rulesetName: string): IDataQualityRuleset {
95+
class Import extends Resource implements IDataQualityRuleset {
96+
public rulesetArn = DataQualityRuleset.buildRulesetArn(scope, rulesetName);
97+
public rulesetName = rulesetName;
98+
}
99+
100+
return new Import(scope, id);
101+
}
102+
103+
private static buildRulesetArn(scope: constructs.Construct, rulesetName: string) : string {
104+
return cdk.Stack.of(scope).formatArn({
105+
service: 'glue',
106+
resource: 'dataqualityruleset',
107+
resourceName: rulesetName,
108+
});
109+
}
110+
111+
/**
112+
* Name of this ruleset.
113+
*/
114+
public readonly rulesetName: string;
115+
116+
/**
117+
* ARN of this ruleset.
118+
*/
119+
public readonly rulesetArn: string;
120+
121+
constructor(scope: constructs.Construct, id: string, props: DataQualityRulesetProps) {
122+
super(scope, id, {
123+
physicalName: props.rulesetName,
124+
});
125+
126+
const rulesetResource = new CfnDataQualityRuleset(this, 'Resource', {
127+
clientToken: props.clientToken,
128+
description: props.description,
129+
name: props.rulesetName,
130+
ruleset: props.rulesetDqdl,
131+
tags: props.tags,
132+
targetTable: props.targetTable,
133+
});
134+
135+
const resourceName = this.getResourceNameAttribute(rulesetResource.ref);
136+
this.rulesetArn = DataQualityRuleset.buildRulesetArn(this, resourceName);
137+
this.rulesetName = resourceName;
138+
}
139+
}

packages/@aws-cdk/aws-glue-alpha/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export * from './connection';
44
export * from './data-format';
5+
export * from './data-quality-ruleset';
56
export * from './database';
67
export * from './job';
78
export * from './job-executable';

packages/@aws-cdk/aws-glue-alpha/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@
8484
"@aws-cdk/cdk-build-tools": "0.0.0",
8585
"@aws-cdk/integ-runner": "0.0.0",
8686
"@aws-cdk/pkglint": "0.0.0",
87+
"@aws-cdk/integ-tests-alpha": "0.0.0",
8788
"@types/jest": "^29.5.1",
88-
"jest": "^29.5.0",
8989
"aws-cdk-lib": "0.0.0",
90-
"constructs": "^10.0.0"
90+
"constructs": "^10.0.0",
91+
"jest": "^29.5.0"
9192
},
9293
"dependencies": {},
9394
"homepage": "https://github.com/aws/aws-cdk",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Template } from 'aws-cdk-lib/assertions';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as glue from '../lib';
4+
5+
test('a data quality ruleset', () => {
6+
const stack = new cdk.Stack();
7+
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', {
8+
description: 'description',
9+
rulesetName: 'ruleset_name',
10+
rulesetDqdl: 'ruleset_dqdl',
11+
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'),
12+
});
13+
14+
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', {
15+
Description: 'description',
16+
Name: 'ruleset_name',
17+
Ruleset: 'ruleset_dqdl',
18+
TargetTable: {
19+
DatabaseName: 'database_name',
20+
TableName: 'table_name',
21+
},
22+
});
23+
});
24+
25+
test('a data quality ruleset with a client token', () => {
26+
const stack = new cdk.Stack();
27+
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', {
28+
clientToken: 'client_token',
29+
description: 'description',
30+
rulesetName: 'ruleset_name',
31+
rulesetDqdl: 'ruleset_dqdl',
32+
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'),
33+
});
34+
35+
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', {
36+
ClientToken: 'client_token',
37+
Description: 'description',
38+
Name: 'ruleset_name',
39+
Ruleset: 'ruleset_dqdl',
40+
TargetTable: {
41+
DatabaseName: 'database_name',
42+
TableName: 'table_name',
43+
},
44+
});
45+
});
46+
47+
test('a data quality ruleset with tags', () => {
48+
const stack = new cdk.Stack();
49+
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', {
50+
clientToken: 'client_token',
51+
description: 'description',
52+
rulesetName: 'ruleset_name',
53+
rulesetDqdl: 'ruleset_dqdl',
54+
tags: {
55+
key1: 'value1',
56+
key2: 'value2',
57+
},
58+
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'),
59+
});
60+
61+
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', {
62+
ClientToken: 'client_token',
63+
Description: 'description',
64+
Name: 'ruleset_name',
65+
Ruleset: 'ruleset_dqdl',
66+
Tags: {
67+
key1: 'value1',
68+
key2: 'value2',
69+
},
70+
TargetTable: {
71+
DatabaseName: 'database_name',
72+
TableName: 'table_name',
73+
},
74+
});
75+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "32.0.0",
3+
"files": {
4+
"b9515accbd6b765c36fbffa5adb190fc8f6d1f67573ab2655ede370368887799": {
5+
"source": {
6+
"path": "aws-glue-data-quality-ruleset.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "b9515accbd6b765c36fbffa5adb190fc8f6d1f67573ab2655ede370368887799.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}

0 commit comments

Comments
 (0)