forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(glue): support Data Quality ruleset (aws#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*
- Loading branch information
1 parent
7c144f8
commit bcc5046
Showing
14 changed files
with
925 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/@aws-cdk/aws-glue-alpha/lib/data-quality-ruleset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as constructs from 'constructs'; | ||
import { IResource, Resource } from 'aws-cdk-lib/core'; | ||
import { CfnDataQualityRuleset } from 'aws-cdk-lib/aws-glue'; | ||
|
||
/** | ||
* Properties of a DataQualityTargetTable. | ||
*/ | ||
export class DataQualityTargetTable { | ||
/** | ||
* The database name of the target table. | ||
*/ | ||
readonly databaseName: string; | ||
|
||
/** | ||
* The table name of the target table. | ||
*/ | ||
readonly tableName: string; | ||
|
||
constructor(databaseName: string, tableName: string) { | ||
this.databaseName = databaseName; | ||
this.tableName = tableName; | ||
} | ||
} | ||
|
||
export interface IDataQualityRuleset extends IResource { | ||
/** | ||
* The ARN of the ruleset | ||
* @attribute | ||
*/ | ||
readonly rulesetArn: string; | ||
|
||
/** | ||
* The name of the ruleset | ||
* @attribute | ||
*/ | ||
readonly rulesetName: string; | ||
} | ||
|
||
/** | ||
* Construction properties for `DataQualityRuleset` | ||
*/ | ||
export interface DataQualityRulesetProps { | ||
/** | ||
* The name of the ruleset | ||
* @default cloudformation generated name | ||
*/ | ||
readonly rulesetName?: string; | ||
|
||
/** | ||
* The client token of the ruleset | ||
* @attribute | ||
*/ | ||
readonly clientToken?: string; | ||
|
||
/** | ||
* The description of the ruleset | ||
* @attribute | ||
*/ | ||
readonly description?: string; | ||
|
||
/** | ||
* The dqdl of the ruleset | ||
* @attribute | ||
*/ | ||
readonly rulesetDqdl: string; | ||
|
||
/** | ||
* Key-Value pairs that define tags for the ruleset. | ||
* @default empty tags | ||
*/ | ||
readonly tags?: { [key: string]: string }; | ||
|
||
/** | ||
* The target table of the ruleset | ||
* @attribute | ||
*/ | ||
readonly targetTable: DataQualityTargetTable; | ||
} | ||
|
||
/** | ||
* A Glue Data Quality ruleset. | ||
*/ | ||
export class DataQualityRuleset extends Resource implements IDataQualityRuleset { | ||
public static fromRulesetArn(scope: constructs.Construct, id: string, rulesetArn: string): IDataQualityRuleset { | ||
class Import extends Resource implements IDataQualityRuleset { | ||
public rulesetArn = rulesetArn; | ||
public rulesetName = cdk.Arn.extractResourceName(rulesetArn, 'dataqualityruleset'); | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
|
||
public static fromRulesetName(scope: constructs.Construct, id: string, rulesetName: string): IDataQualityRuleset { | ||
class Import extends Resource implements IDataQualityRuleset { | ||
public rulesetArn = DataQualityRuleset.buildRulesetArn(scope, rulesetName); | ||
public rulesetName = rulesetName; | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
|
||
private static buildRulesetArn(scope: constructs.Construct, rulesetName: string) : string { | ||
return cdk.Stack.of(scope).formatArn({ | ||
service: 'glue', | ||
resource: 'dataqualityruleset', | ||
resourceName: rulesetName, | ||
}); | ||
} | ||
|
||
/** | ||
* Name of this ruleset. | ||
*/ | ||
public readonly rulesetName: string; | ||
|
||
/** | ||
* ARN of this ruleset. | ||
*/ | ||
public readonly rulesetArn: string; | ||
|
||
constructor(scope: constructs.Construct, id: string, props: DataQualityRulesetProps) { | ||
super(scope, id, { | ||
physicalName: props.rulesetName, | ||
}); | ||
|
||
const rulesetResource = new CfnDataQualityRuleset(this, 'Resource', { | ||
clientToken: props.clientToken, | ||
description: props.description, | ||
name: props.rulesetName, | ||
ruleset: props.rulesetDqdl, | ||
tags: props.tags, | ||
targetTable: props.targetTable, | ||
}); | ||
|
||
const resourceName = this.getResourceNameAttribute(rulesetResource.ref); | ||
this.rulesetArn = DataQualityRuleset.buildRulesetArn(this, resourceName); | ||
this.rulesetName = resourceName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/@aws-cdk/aws-glue-alpha/test/data-quality-ruleset.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Template } from 'aws-cdk-lib/assertions'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as glue from '../lib'; | ||
|
||
test('a data quality ruleset', () => { | ||
const stack = new cdk.Stack(); | ||
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', { | ||
description: 'description', | ||
rulesetName: 'ruleset_name', | ||
rulesetDqdl: 'ruleset_dqdl', | ||
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'), | ||
}); | ||
|
||
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', { | ||
Description: 'description', | ||
Name: 'ruleset_name', | ||
Ruleset: 'ruleset_dqdl', | ||
TargetTable: { | ||
DatabaseName: 'database_name', | ||
TableName: 'table_name', | ||
}, | ||
}); | ||
}); | ||
|
||
test('a data quality ruleset with a client token', () => { | ||
const stack = new cdk.Stack(); | ||
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', { | ||
clientToken: 'client_token', | ||
description: 'description', | ||
rulesetName: 'ruleset_name', | ||
rulesetDqdl: 'ruleset_dqdl', | ||
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'), | ||
}); | ||
|
||
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', { | ||
ClientToken: 'client_token', | ||
Description: 'description', | ||
Name: 'ruleset_name', | ||
Ruleset: 'ruleset_dqdl', | ||
TargetTable: { | ||
DatabaseName: 'database_name', | ||
TableName: 'table_name', | ||
}, | ||
}); | ||
}); | ||
|
||
test('a data quality ruleset with tags', () => { | ||
const stack = new cdk.Stack(); | ||
new glue.DataQualityRuleset(stack, 'DataQualityRuleset', { | ||
clientToken: 'client_token', | ||
description: 'description', | ||
rulesetName: 'ruleset_name', | ||
rulesetDqdl: 'ruleset_dqdl', | ||
tags: { | ||
key1: 'value1', | ||
key2: 'value2', | ||
}, | ||
targetTable: new glue.DataQualityTargetTable('database_name', 'table_name'), | ||
}); | ||
|
||
Template.fromStack(stack).hasResourceProperties('AWS::Glue::DataQualityRuleset', { | ||
ClientToken: 'client_token', | ||
Description: 'description', | ||
Name: 'ruleset_name', | ||
Ruleset: 'ruleset_dqdl', | ||
Tags: { | ||
key1: 'value1', | ||
key2: 'value2', | ||
}, | ||
TargetTable: { | ||
DatabaseName: 'database_name', | ||
TableName: 'table_name', | ||
}, | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...pha/test/integ.data-quality-ruleset.js.snapshot/aws-glue-data-quality-ruleset.assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "32.0.0", | ||
"files": { | ||
"b9515accbd6b765c36fbffa5adb190fc8f6d1f67573ab2655ede370368887799": { | ||
"source": { | ||
"path": "aws-glue-data-quality-ruleset.template.json", | ||
"packaging": "file" | ||
}, | ||
"destinations": { | ||
"current_account-current_region": { | ||
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", | ||
"objectKey": "b9515accbd6b765c36fbffa5adb190fc8f6d1f67573ab2655ede370368887799.json", | ||
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" | ||
} | ||
} | ||
} | ||
}, | ||
"dockerImages": {} | ||
} |
Oops, something went wrong.