Skip to content

Datazone+Glue Integration for Column Level Lineage

0

Hi

I am using Glue 5.0. I have updated the job configuration to export lineage. However in Datazone I don't see the column level lineage. Given below is sample code and configs for reference.

from pyspark.context import SparkContext from pyspark.sql import SparkSession from awsglue.context import GlueContext from awsglue.dynamicframe import DynamicFrame from awsglue.transforms import ResolveChoice,ApplyMapping, Filter, SelectFields, DropFields from awsglue.job import Job

Initialize Spark and Glue context

sc = SparkContext.getOrCreate() glueContext = GlueContext(sc) spark = glueContext.spark_session job = Job(glueContext)

Initialize job

job.init("SimpleGlueJob")

Hardcoded database and table names

source_database = "a_bronze" source_table = "a_bronze_e" target_database = "a_silver" target_table = "a_silver_e"

source_df = glueContext.create_dynamic_frame.from_catalog( database=source_database, table_name=source_table, transformation_ctx="a_bronze" )

#keeps all columns, transforms only required column_transformations = {"e_salary": "int"}

mappings = [] for field in source_df.schema(): fname = field.name stype = field.dataType.typeName() ttype = column_transformations.get(fname, stype) mappings.append((fname, stype, fname, ttype))

transformed_df = ApplyMapping.apply(frame=source_df, mappings=mappings, transformation_ctx="stringtoint")

Write the transformed data to Glue Catalog

glueContext.write_dynamic_frame.from_catalog( frame = transformed_df, database = target_database, table_name = target_table, transformation_ctx="a_silver" )

Commit job

job.commit()

from pyspark.context import SparkContext from pyspark.sql import SparkSession from awsglue.context import GlueContext from awsglue.dynamicframe import DynamicFrame from awsglue.transforms import ResolveChoice,ApplyMapping, Filter, SelectFields, DropFields from awsglue.job import Job

Initialize Spark and Glue context

sc = SparkContext.getOrCreate() glueContext = GlueContext(sc) spark = glueContext.spark_session job = Job(glueContext)

Initialize job

job.init("SimpleGlueJob")

Hardcoded database and table names

source_database = "a_bronze" source_table = "a_bronze_e" target_database = "a_silver" target_table = "a_silver_e"

source_df = glueContext.create_dynamic_frame.from_catalog( database=source_database, table_name=source_table, transformation_ctx="a_bronze" )

#keeps all columns, transforms only required column_transformations = {"e_salary": "int"}

mappings = [] for field in source_df.schema(): fname = field.name stype = field.dataType.typeName() ttype = column_transformations.get(fname, stype) mappings.append((fname, stype, fname, ttype))

transformed_df = ApplyMapping.apply(frame=source_df, mappings=mappings, transformation_ctx="stringtoint")

Write the transformed data to Glue Catalog

glueContext.write_dynamic_frame.from_catalog( frame = transformed_df, database = target_database, table_name = target_table, transformation_ctx="a_silver" )

Commit job

job.commit()

Configurations

  1. Check - Generate Job insights, Generate Lineage Events
  2. Datazone domain and project created. Datasources mapped to pick these database tables.
  3. Datazone blueprints, env, env profile all created with roles have permissions to access catalog (Used default templates)
  4. Glue IAM role also has permissions/inline policies

asked a year ago207 views

1 Answer
0

To enable column-level lineage in Amazon DataZone when using AWS Glue 5.0, you need to ensure that your configuration is properly set up to capture and transmit the detailed lineage information.

Based on your code and configuration, you've correctly enabled the "Generate Lineage Events" option in your Glue job and connected it to your DataZone domain. However, to capture column-level lineage specifically, you need to make sure you're using the OpenLineage integration correctly.

Here are some recommendations to ensure column-level lineage is captured:

  1. Make sure you've provided the correct DataZone domain ID in your job configuration. This should be in the format:
--conf spark.extraListeners=io.openlineage.spark.agent.OpenLineageSparkListener --conf spark.openlineage.transport.type=amazon_datazone_api --conf spark.openlineage.transport.domainId=<Your-Domain-ID>
  1. Ensure your transformation context names are meaningful and consistent. In your code, you're using "a_bronze", "stringtoint", and "a_silver" as transformation contexts, which is good practice.

  2. The ApplyMapping transform you're using should help with column-level lineage, as it explicitly maps source columns to target columns. However, make sure the mappings are correctly defined.

  3. Verify that the AWS Glue job role has the necessary permissions to send lineage events to Amazon DataZone.

  4. After running the job, it may take some time for the lineage information to be processed and displayed in DataZone. Try refreshing or waiting a bit after the job completes.

  5. If you're using AWS Glue Data Catalog tables (which you are), make sure they are properly added to the Amazon DataZone catalog through data source runs.

If you've verified all these points and still don't see column-level lineage, you might want to check if there are any errors in the job logs related to lineage event generation or transmission to DataZone.
Sources
Introducing AWS Glue 5.0 for Apache Spark | AWS Big Data Blog
Data lineage in Amazon DataZone - Amazon DataZone
Migrating AWS Glue for Spark jobs to AWS Glue version 5.0 - AWS Glue
Announcing the general availability of data lineage in the next generation of Amazon SageMaker and Amazon DataZone | AWS News Blog

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.