

# Column-level lineage

Column-level lineage records, for each column of an output dataset, the input columns it was derived from and how. Use it to find which reports use a sensitive column, or to see what breaks if you rename a column.

## How column lineage is captured
<a name="how-column-lineage-is-captured"></a>

Column lineage comes from the OpenLineage `columnLineage` dataset facet on output datasets.
+ **Amazon EMR and AWS Glue.** The Spark listener derives column lineage from the query plan. The service sets `spark.openlineage.columnLineage.datasetLineageEnabled=true`.
+ **Your own events.** Include the `columnLineage` facet.

## Transformation types
<a name="transformation-types"></a>

Each input field in the facet has transformations that describe how it contributes to the output column:


| Type | Subtype | Meaning | Example | 
| --- | --- | --- | --- | 
| DIRECT | IDENTITY | The value is copied | SELECT id FROM orders | 
| DIRECT | TRANSFORMATION | The value is computed from the input | upper(name), masking | 
| DIRECT | AGGREGATION | The value is aggregated | sum(amount) | 
| INDIRECT | JOIN, FILTER, GROUP\_BY, SORT, WINDOW, CONDITIONAL | The input affects the output without being copied | WHERE region = 'east' | 

A transformation can also have a `masking` flag that shows the value was masked or hashed.

## Example – columnLineage facet
<a name="example-facet"></a>

```json
"columnLineage": {
  "_producer": "https://example.com/producer",
  "_schemaURL": "https://openlineage.io/spec/facets/1-2-0/ColumnLineageDatasetFacet.json",
  "fields": {
    "total": {
      "inputFields": [
        {
          "namespace": "arn:aws:glue:us-east-1:111122223333",
          "name": "table/sales_db/orders",
          "field": "amount",
          "transformations": [{ "type": "DIRECT", "subtype": "AGGREGATION" }]
        }
      ]
    }
  }
}
```

## Viewing column lineage
<a name="viewing-column-lineage"></a>
+ **Console.** Expand the columns on a dataset node and choose a column.
+ **API.** `GetLineageNode` returns column lineage for a dataset node in `FormsOutput`, in the `ColumnLineage` form. Transformations that apply to the whole dataset, such as a filter or join, are returned in the `GlobalTransformations` form.
+ **SQL.** Read the facet from `event_payload_json` in the lineage system table.

`GetLineageNode` stores and returns INDIRECT transformations. The console might not show the transformation type or INDIRECT edges.

## Limitations
<a name="limitations"></a>
+ Column lineage depends on the engine being able to analyze the query. Some user-defined functions and complex DataFrame operations produce partial column lineage.
+ Column lineage from Amazon DataZone might not carry over during migration.