In the data analytics space, organizations often deal with many tables in different databases and file formats to hold data for different business functions. Business needs often drive table structure, such as schema evolution (the addition of new columns, removal of existing columns, update of column names, and so on) for some of these tables in one business function that requires other business functions to replicate the same. This post focuses on such schema changes in file-based tables and shows how to automatically replicate the schema evolution of structured data from table formats in databases to the tables stored as files in cost-effective way.
AWS Glue is a serverless data integration service that makes it easy to discover, prepare, and combine data for analytics, machine learning (ML), and application development. In this post, we show how to use Apache Hudi, a self-managing database layer on file-based data lakes, in AWS Glue to automatically represent data in relational form and manage their schema evolution at scale using Amazon Simple Storage Service (Amazon S3), AWS Database Migration Service (AWS DMS), AWS Lambda, AWS Glue, Amazon DynamoDB, Amazon Aurora, and Amazon Athena to automatically identify schema evolution and apply it to manage data load at petabyte scale.
Apache Hudi supports ACID transactions and CRUD operations on a data lake. This lays the foundation of a data lake architecture by enabling transaction support and schema evolution and management, decoupling storage from compute, and ensuring support for accessibility through business intelligence (BI) tools. In this post, we implement an architecture to build a transactional data lake built on the aforementioned Hudi features.
This post assumes a scenario where multiple tables are present in a source database, and we want to replicate any schema changes in any of those tables in Apache Hudi tables in the data lake. It uses the native support for Apache Hudi on AWS Glue for Apache Spark.
In this post, the schema evolution of source tables in the Aurora database is captured via the AWS DMS incremental load or change data capture (CDC) mechanism, and the same schema evolution is replicated in Apache Hudi tables stored in Amazon S3. Apache Hudi tables are discovered by the AWS Glue Data Catalog and queried by Athena. An AWS Glue job, supported by an orchestration pipeline using Lambda and a DynamoDB table, takes care of the automated replication of schema evolution in the Apache Hudi tables.
We use Aurora as a sample data source, but any data source that supports Create, Read, Update, and Delete (CRUD) operations can replace Aurora in your use case.
The following diagram illustrates our solution architecture.

The flow of the solution is as follows:
We provide an AWS CloudFormation template to create the following resources:
The Aurora table and AWS DMS replication instance is not provisioned via this stack. For instructions to set up Aurora, refer to Creating an Amazon Aurora DB cluster.
Launch the following stack and provide your stack name.
eu-west-1 |
To access your Aurora database, refer to How do I connect to my Amazon RDS for MySQL instance by using MySQL Workbench. Then complete the following steps:
After you create the stacks, some manual steps are needed to prepare the solution end to end.
raw-bucket-<account\_number>-<region\_name>, and the folder name should be POC.HudiLambda Lambda function with the content of the event JSON as POC.db and save it.In this post, the schema evolution is reflected through Hudi Hive sync in AWS Glue. You don’t alter queries separately in the data lake.
Now we complete the following steps to change the schema at the source. Trigger the Lambda function after each step to generate a file in the POC/db/object folder within the raw bucket. AWS DMS almost instantly picks up the schema changes and reports to the raw bucket.
test\_column to the source table object in your Aurora database:new\_field\_1 to new\_field\_2 in the source table object:The column new\_field\_1 is expected to stay in the Hudi table but without any new values being populated to it anymore.
new\_field\_2 from the source table object:Similar to the previous operation, the column new\_field\_2 is expected to stay in the Hudi table but without any new values being populated to it anymore.
If you already have AWS Lake Formation data permissions set up in your account, you may encounter permission issues. In that case, grant full permission (Super) to the default database (before triggering the Lambda function) and all tables in the POC.db database (after the load is complete).
When the aforementioned run happens after schema changes, the following results are generated in the refined bucket. We can view the Apache Hudi tables with its contents in Athena. To set up Athena, refer to Getting started.
The table and the database are available in the AWS Glue Data Catalog and ready for browsing the schema.
Before the schema change, the Athena results look like the following screenshot.

After you add the column test\_column and insert a value in the test\_column field in the object table in the Aurora database, the new column (test\_column) is reflected in its corresponding Apache Hudi table in the data lake.
The following screenshot shows the results in Athena.

After you rename the column new\_field\_1 to new\_field\_2 and insert a value in the new\_field\_2 field in the object table, the renamed column (new\_field\_2) is reflected in its corresponding Apache Hudi table in the data lake, and new\_field\_1 remains in the schema, having no new value populated to the column.
The following screenshot shows the results in Athena.

After you delete the column new\_field\_2 in the object table and insert or update any values under any columns in the object table, the deleted column (new\_field\_2) remains in the corresponding Apache Hudi table schema, having no new value populated to the column.
The following screenshot shows the results in Athena.

When you’re done with this solution, delete the sample data in the raw and refined S3 buckets and delete the buckets.
Also, delete the CloudFormation stack to remove all the service resources used in this solution.
This post showed how to implement schema evolution with an open-source solution using Apache Hudi in an AWS environment with an orchestration pipeline.
You can explore the different configurations of AWS Glue to change the AWS Glue job structures and implement it for your data analytics and other use cases.
Subhro Bose is a Senior Data Architect in Emergent Technologies and Intelligence Platform in Amazon. He loves solving science problems with emergent technologies such as AI/ML, big data, quantum, and more to help businesses across different industry verticals succeed within their innovation journey. In his spare time, he enjoys playing table tennis, learn theories of environmental economics and explore the best muffins across the city.
Ketan Karalkar is a Big Data Solutions Consultant at AWS. He has nearly 2 decades of experience helping customers design and build data analytics, and database solutions. He believes in using technology as an enabler to solve real life business problems.
Eva Fang is a Data Scientist within Professional Services in AWS. She is passionate about using the technology to provide value to customers and achieve business outcomes. She is based in London, in her spare time, she likes to watch movies and musicals.