-
Notifications
You must be signed in to change notification settings - Fork 10
DATAPLT-1268 Add shortcut for Iceberg-backed Glue Table #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jeffhiltz
wants to merge
6
commits into
master
Choose a base branch
from
dataplt-1268-create_glue_iceberg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc4665d
initial version of Iceberg-backed Glue Table
jeffhiltz 95dcd92
add compaction configuration to Glue Iceberg tables
jeffhiltz d84839d
add orphan file deletion configuration to Glue Iceberg tables
jeffhiltz 6b02cec
remove the compaction config which is in the api but not CFN
jeffhiltz 87e8333
update cfn-lint to get newer property types
jeffhiltz 7c01d48
update sam-cli in order to update cfn-lint
jeffhiltz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,207 @@ | ||
| 'use strict'; | ||
|
|
||
| const GlueTable = require('./glue-table'); | ||
|
|
||
| /** | ||
| * Create a Glue table backed by Apache Iceberg format on S3. | ||
| * | ||
| * @param {Object} options - Accepts the same options as cloudfriend's | ||
| * [`GlueTable`](https://github.com/mapbox/cloudfriend/blob/master/lib/shortcuts/glue-table.js), | ||
| * though the following additional attributes are either required or hard-wired: | ||
| * @param {String} options.Location - The physical location of the table. See | ||
| * [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-storagedescriptor.html#cfn-glue-table-storagedescriptor-location). | ||
| * @param {String} [options.TableType='EXTERNAL_TABLE'] - Hard-wired by this | ||
| * shortcut. | ||
| * @param {String} [options.IcebergVersion='2'] - The table version for the | ||
| * Iceberg table. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-table-iceberginput.html). | ||
| * @param {Boolean} [options.EnableOptimizer=false] - Whether to enable the | ||
| * snapshot retention optimizer for this Iceberg table. | ||
| * @param {String} [options.OptimizerRoleArn=undefined] - The ARN of the IAM | ||
| * role for the retention optimizer to use. Required if EnableOptimizer is | ||
| * true. Can be the same role as CompactionRoleArn or OrphanFileDeletionRoleArn | ||
| * if multiple optimizers are enabled. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-tableoptimizer-tableoptimizerconfiguration.html). | ||
| * @param {Number} [options.SnapshotRetentionPeriodInDays=5] - The number of | ||
| * days to retain snapshots. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-glue-tableoptimizer-icebergretentionconfiguration.html). | ||
| * @param {Number} [options.NumberOfSnapshotsToRetain=1] - The minimum number | ||
| * of snapshots to retain. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-glue-tableoptimizer-icebergretentionconfiguration.html). | ||
| * @param {Boolean} [options.CleanExpiredFiles=true] - Whether to delete | ||
| * expired data files after expiring snapshots. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-glue-tableoptimizer-icebergretentionconfiguration.html). | ||
| * @param {Boolean} [options.EnableCompaction=false] - Whether to enable the | ||
| * compaction optimizer for this Iceberg table. Note: CloudFormation does not | ||
| * support configuring compaction strategy or thresholds; the optimizer will use | ||
| * AWS defaults (binpack strategy). Configuration must be done via AWS CLI/API. | ||
| * See [GitHub issue](https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/2257). | ||
| * @param {String} [options.CompactionRoleArn=undefined] - The ARN of the IAM | ||
| * role for the compaction optimizer to use. Required if EnableCompaction is | ||
| * true. Can be the same role as OptimizerRoleArn or OrphanFileDeletionRoleArn | ||
| * if multiple optimizers are enabled. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-tableoptimizer-tableoptimizerconfiguration.html). | ||
| * @param {Boolean} [options.EnableOrphanFileDeletion=false] - Whether to | ||
| * enable the orphan file deletion optimizer for this Iceberg table. | ||
| * @param {String} [options.OrphanFileDeletionRoleArn=undefined] - The ARN of | ||
| * the IAM role for the orphan file deletion optimizer to use. Required if | ||
| * EnableOrphanFileDeletion is true. Can be the same role as OptimizerRoleArn | ||
| * or CompactionRoleArn if multiple optimizers are enabled. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-glue-tableoptimizer-tableoptimizerconfiguration.html). | ||
| * @param {Number} [options.OrphanFileRetentionPeriodInDays=3] - The number of | ||
| * days to retain orphan files before deleting them. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/glue/latest/dg/enable-orphan-file-deletion.html). | ||
| * @param {String} [options.OrphanFileDeletionLocation=undefined] - The S3 | ||
| * location to scan for orphan files. Defaults to the table location if not | ||
| * specified. See [AWS | ||
| * documentation](https://docs.aws.amazon.com/glue/latest/dg/enable-orphan-file-deletion.html). | ||
| */ | ||
| class GlueIcebergTable extends GlueTable { | ||
| constructor(options) { | ||
| if (!options) throw new Error('Options required'); | ||
| const { | ||
| Location, | ||
| IcebergVersion = '2', | ||
| EnableOptimizer = false, | ||
| OptimizerRoleArn, | ||
| SnapshotRetentionPeriodInDays = 5, | ||
| NumberOfSnapshotsToRetain = 1, | ||
| CleanExpiredFiles = true, | ||
| EnableCompaction = false, | ||
| CompactionRoleArn, | ||
| EnableOrphanFileDeletion = false, | ||
| OrphanFileDeletionRoleArn, | ||
| OrphanFileRetentionPeriodInDays = 3, | ||
| OrphanFileDeletionLocation | ||
| } = options; | ||
|
|
||
| const required = [Location]; | ||
| if (required.some((variable) => !variable)) | ||
| throw new Error('You must provide a Location'); | ||
|
|
||
| if (EnableOptimizer && !OptimizerRoleArn) | ||
| throw new Error('You must provide an OptimizerRoleArn when EnableOptimizer is true'); | ||
|
|
||
| if (EnableCompaction && !CompactionRoleArn) | ||
| throw new Error('You must provide a CompactionRoleArn when EnableCompaction is true'); | ||
|
|
||
| if (EnableOrphanFileDeletion && !OrphanFileDeletionRoleArn) | ||
| throw new Error('You must provide an OrphanFileDeletionRoleArn when EnableOrphanFileDeletion is true'); | ||
|
|
||
| super( | ||
| Object.assign( | ||
| { | ||
| TableType: 'EXTERNAL_TABLE', | ||
| Parameters: { EXTERNAL: 'TRUE' } | ||
| }, | ||
| options | ||
| ) | ||
| ); | ||
|
|
||
| const logicalName = options.LogicalName; | ||
| this.Resources[logicalName].Properties.OpenTableFormatInput = { | ||
| IcebergInput: { | ||
| MetadataOperation: 'CREATE', | ||
| Version: IcebergVersion | ||
| } | ||
| }; | ||
|
|
||
| // Optionally add TableOptimizer for configuring snapshot retention | ||
| if (EnableOptimizer) { | ||
| const optimizerLogicalName = `${logicalName}RetentionOptimizer`; | ||
| this.Resources[optimizerLogicalName] = { | ||
| Type: 'AWS::Glue::TableOptimizer', | ||
| DependsOn: logicalName, | ||
| Properties: { | ||
| CatalogId: options.CatalogId || { Ref: 'AWS::AccountId' }, | ||
| DatabaseName: options.DatabaseName, | ||
| TableName: options.Name, | ||
| Type: 'retention', | ||
| TableOptimizerConfiguration: { | ||
| RoleArn: OptimizerRoleArn, | ||
| Enabled: true, | ||
| RetentionConfiguration: { | ||
| IcebergConfiguration: { | ||
| SnapshotRetentionPeriodInDays, | ||
| NumberOfSnapshotsToRetain, | ||
| CleanExpiredFiles | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Apply Condition to optimizer if specified on the table | ||
| if (options.Condition) { | ||
| this.Resources[optimizerLogicalName].Condition = options.Condition; | ||
| } | ||
| } | ||
|
|
||
| // Optionally add TableOptimizer for compaction | ||
| // NOTE: CloudFormation does not support CompactionConfiguration properties | ||
| // (strategy, minInputFiles, deleteFileThreshold). These must be configured | ||
| // via AWS CLI/API after stack creation, or will use AWS defaults. | ||
| // See: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/2257 | ||
| if (EnableCompaction) { | ||
| const compactionLogicalName = `${logicalName}CompactionOptimizer`; | ||
| this.Resources[compactionLogicalName] = { | ||
| Type: 'AWS::Glue::TableOptimizer', | ||
| DependsOn: logicalName, | ||
| Properties: { | ||
| CatalogId: options.CatalogId || { Ref: 'AWS::AccountId' }, | ||
| DatabaseName: options.DatabaseName, | ||
| TableName: options.Name, | ||
| Type: 'compaction', | ||
| TableOptimizerConfiguration: { | ||
| RoleArn: CompactionRoleArn, | ||
| Enabled: true | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Apply Condition to compaction optimizer if specified on the table | ||
| if (options.Condition) { | ||
| this.Resources[compactionLogicalName].Condition = options.Condition; | ||
| } | ||
| } | ||
|
|
||
| // Optionally add TableOptimizer for orphan file deletion | ||
| if (EnableOrphanFileDeletion) { | ||
| const orphanLogicalName = `${logicalName}OrphanFileDeletionOptimizer`; | ||
| const icebergConfiguration = { | ||
| OrphanFileRetentionPeriodInDays | ||
| }; | ||
|
|
||
| // Only add Location if specified, otherwise it defaults to table location | ||
| if (OrphanFileDeletionLocation) { | ||
| icebergConfiguration.Location = OrphanFileDeletionLocation; | ||
| } | ||
|
|
||
| this.Resources[orphanLogicalName] = { | ||
| Type: 'AWS::Glue::TableOptimizer', | ||
| DependsOn: logicalName, | ||
| Properties: { | ||
| CatalogId: options.CatalogId || { Ref: 'AWS::AccountId' }, | ||
| DatabaseName: options.DatabaseName, | ||
| TableName: options.Name, | ||
| Type: 'orphan_file_deletion', | ||
| TableOptimizerConfiguration: { | ||
| RoleArn: OrphanFileDeletionRoleArn, | ||
| Enabled: true, | ||
| OrphanFileDeletionConfiguration: { | ||
| IcebergConfiguration: icebergConfiguration | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Apply Condition to orphan file deletion optimizer if specified on the table | ||
| if (options.Condition) { | ||
| this.Resources[orphanLogicalName].Condition = options.Condition; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = GlueIcebergTable; | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| aws-sam-cli==1.142.1 | ||
| cfn-lint==1.36.1 | ||
| aws-sam-cli==1.149.0 | ||
| cfn-lint==1.41.0 |
This file contains hidden or 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,50 @@ | ||
| { | ||
| "AWSTemplateFormatVersion": "2010-09-09", | ||
| "Metadata": {}, | ||
| "Parameters": {}, | ||
| "Rules": {}, | ||
| "Mappings": {}, | ||
| "Conditions": {}, | ||
| "Resources": { | ||
| "MyTable": { | ||
| "Type": "AWS::Glue::Table", | ||
| "Properties": { | ||
| "CatalogId": { | ||
| "Ref": "AWS::AccountId" | ||
| }, | ||
| "DatabaseName": "my_database", | ||
| "TableInput": { | ||
| "Description": { | ||
| "Fn::Sub": "Created by the ${AWS::StackName} CloudFormation stack" | ||
| }, | ||
| "Name": "my_table", | ||
| "Parameters": { | ||
| "EXTERNAL": "TRUE" | ||
| }, | ||
| "PartitionKeys": [], | ||
| "TableType": "EXTERNAL_TABLE", | ||
| "StorageDescriptor": { | ||
| "Columns": [ | ||
| { | ||
| "Name": "column", | ||
| "Type": "string" | ||
| } | ||
| ], | ||
| "Compressed": false, | ||
| "Location": "s3://fake/location", | ||
| "NumberOfBuckets": 0, | ||
| "SerdeInfo": {}, | ||
| "StoredAsSubDirectories": true | ||
| } | ||
| }, | ||
| "OpenTableFormatInput": { | ||
| "IcebergInput": { | ||
| "MetadataOperation": "CREATE", | ||
| "Version": "2" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "Outputs": {} | ||
| } |
60 changes: 60 additions & 0 deletions
60
test/fixtures/shortcuts/glue-iceberg-table-no-defaults.json
This file contains hidden or 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,60 @@ | ||
| { | ||
| "AWSTemplateFormatVersion": "2010-09-09", | ||
| "Metadata": {}, | ||
| "Parameters": {}, | ||
| "Rules": {}, | ||
| "Mappings": {}, | ||
| "Conditions": { | ||
| "Always": { | ||
| "Fn::Equals": [ | ||
| "1", | ||
| "1" | ||
| ] | ||
| } | ||
| }, | ||
| "Resources": { | ||
| "AnotherThing": { | ||
| "Type": "AWS::SNS::Topic" | ||
| }, | ||
| "MyTable": { | ||
| "Type": "AWS::Glue::Table", | ||
| "Condition": "Always", | ||
| "DependsOn": "AnotherThing", | ||
| "Properties": { | ||
| "CatalogId": "1234", | ||
| "DatabaseName": "my_database", | ||
| "TableInput": { | ||
| "Description": "my_table description", | ||
| "Name": "my_table", | ||
| "Owner": "Team", | ||
| "Parameters": { | ||
| "table": "params" | ||
| }, | ||
| "PartitionKeys": [], | ||
| "Retention": 12, | ||
| "TableType": "EXTERNAL_TABLE", | ||
| "StorageDescriptor": { | ||
| "Columns": [ | ||
| { | ||
| "Name": "column", | ||
| "Type": "string" | ||
| } | ||
| ], | ||
| "Compressed": false, | ||
| "Location": "s3://fake/location", | ||
| "NumberOfBuckets": 0, | ||
| "SerdeInfo": {}, | ||
| "StoredAsSubDirectories": true | ||
| } | ||
| }, | ||
| "OpenTableFormatInput": { | ||
| "IcebergInput": { | ||
| "MetadataOperation": "CREATE", | ||
| "Version": "2" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "Outputs": {} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.