Area: API
Sub-Area: Lineage API
Applies to: OSS + Cloud
Issue
You want to read lineage that is more than one hop away from an entity through the API. A query returns only direct neighbors, or you don't know which parameters a lineage call needs.
You Might Be Asking
- Why does my lineage query return only one degree of lineage?
- How do I get multi-degree lineage with the Python SDK?
- How do I get multi-degree lineage with GraphQL?
- Do I have to set a time range?
Cause
The hop limit depends on which call you use. There is no single default.
- The GraphQL
lineagefield on an entity always returns one hop. It has no hop input.startdefaults to 0 andcountdefaults to 100. - The Python SDK
get_lineageusesmax_hops=1by default. -
searchAcrossLineageandscrollAcrossLineagehave no one-hop default. You limit hops with adegreefilter. A filter value of"1"gives 1 hop and"2"gives 2 hops. A value of"3+", or no degree filter, applies no limit from the client.
A time range is optional. startTimeMillis and endTimeMillis are optional fields, so you don't need them to get multi-degree results.
Solution
Python SDK
Create the client with DataHubClient.from_env() and call lineage.get_lineage. Use a lowercase direction, and pass source_urn and max_hops:
from datahub.sdk import DataHubClient
client = DataHubClient.from_env()
results = client.lineage.get_lineage(
source_urn="urn:li:dataset:(...)",
direction="downstream", # or "upstream" (default)
max_hops=3,
)
for r in results:
print(r.urn, r.hops)
Notes:
- The method has no
urnordegreesparameter. -
max_hopsof 1 or 2 searches degrees 1 or 1 and 2. - A
max_hopsabove 2 searches the full graph (degrees 1, 2 and 3+). The SDK logs a warning and returns at mostcountresults (500 by default). - To get column-level lineage, pass
source_column.
See the lineage tutorial for more get_lineage examples.
GraphQL
searchAcrossLineage and scrollAcrossLineage need urn (the starting entity) and direction (required). Set hops with a degree filter:
{
scrollAcrossLineage(
input: {
urn: "urn:li:dataset:(...)"
direction: DOWNSTREAM
count: 100
orFilters: [
{ and: [{ field: "degree", condition: EQUAL, values: ["1", "2", "3+"] }] }
]
}
) {
nextScrollId
searchResults {
degree
entity { urn type }
}
}
}
The value "3+" covers three or more hops. scrollAcrossLineage pages with scrollId and nextScrollId. It has no start field. See ScrollAcrossLineageInput.
Optional time filter
To limit results by time, set lineageFlags { startTimeMillis endTimeMillis } in the input. See LineageFlags. The direct startTimeMillis and endTimeMillis fields still work on both queries. On searchAcrossLineage they are marked deprecated in favor of lineageFlags.
Cloud endpoint
On DataHub Cloud, send GraphQL requests to https://<your-account>.acryl.io/api/graphql with the header Authorization: Bearer <token>. See DataHub Cloud GraphQL getting started.