Learn to manage data lineage with the OpenMetadata Java SDK. Fluent API for querying, creating, deleting and exporting lineage with column-level mapping and impact analysis.
The Java SDK provides a fluent API for managing data lineage in OpenMetadata. You can query lineage graphs, create edges between entities with column-level mapping, delete edges, export lineage, and run impact analysis.The fluent entry point is the Lineage class in org.openmetadata.sdk.api.
Lineage in OpenMetadata is a relationship between any two entities. While the examples below use tables and dashboards,
the same API works with any entity type (pipelines, topics, ML models, etc.).
Retrieve the lineage graph for an entity by type and ID:
import org.openmetadata.sdk.api.Lineage;// Get lineage with default depth (1 upstream, 1 downstream)Lineage.LineageGraph graph = Lineage.of("table", tableId).fetch();// Get the raw JSON responseString raw = graph.getRaw();
Each target column in toColumns will be mapped to all columns in fromColumns. The resulting payload includes
a columnsLineage array inside lineageDetails.
To find the entities affected by a change, fetch the lineage graph in one direction and read the entities from the raw JSON. The nodes array lists every entity in the graph.
For simpler use cases, the LineageAPI class in org.openmetadata.sdk.api provides static methods
that wrap the underlying HTTP calls. They use a shared client, which you set up once with OpenMetadata.initialize:
import java.util.Map;import org.openmetadata.sdk.api.LineageAPI;import org.openmetadata.sdk.client.OpenMetadata;OpenMetadata.initialize("http://localhost:8585/api", "<YOUR-JWT-TOKEN>");// Get lineage by entity FQNString lineage = LineageAPI.getLineage("table/name/service.db.schema.table");// Get lineage with depthString lineageWithDepth = LineageAPI.getLineage("table/name/service.db.schema.table", "3", "2");// Get lineage by entity type and IDString lineageById = LineageAPI.getEntityLineage("table", tableId);// Add lineage (pass a Map matching the AddLineage JSON schema)Map<String, Object> lineageRequestMap = Map.of("edge", Map.of( "fromEntity", Map.of("id", sourceTableId, "type", "table"), "toEntity", Map.of("id", targetTableId, "type", "table")));String result = LineageAPI.addLineage(lineageRequestMap);// Delete lineageString deleted = LineageAPI.deleteLineage("table:" + sourceTableId, "dashboard:" + dashboardId);// Export lineageString csv = LineageAPI.exportLineage("service.db.schema.table", "table", "3", "2");