Area: API
Sub-Area: Lineage API
Applies to: OSS + Cloud
Issue
You want to filter lineage results by a time window in the searchAcrossLineage or scrollAcrossLineage GraphQL queries. You are not sure whether to use the direct startTimeMillis and endTimeMillis fields or the lineageFlags object.
You Might Be Asking
- How do I filter lineage queries by time range in GraphQL?
- What is the difference between
startTimeMillisandlineageFlags? - How do I use time filters in
scrollAcrossLineage? - Which fields are required in a
searchAcrossLineagecall?
Cause
Both queries accept a time window in two ways:
- The
lineageFlagsobject. SetstartTimeMillisandendTimeMillisinside it. Both are optional. - The direct
startTimeMillisandendTimeMillisfields on the input.
Both queries handle the direct fields the same way. If lineageFlags does not set a start or end time, the server copies the direct field into lineageFlags. If you give only a start time through the direct field, the end time defaults to now.
The only difference is in the schema. SearchAcrossLineageInput marks the direct fields as deprecated ("Use LineageFlags instead"). ScrollAcrossLineageInput does not. The direct fields still work on both queries.
Solution
Use lineageFlags for new queries. Every query needs urn (the starting entity) and direction (UPSTREAM or DOWNSTREAM). direction is required.
lineageFlags also supports entitiesExploredPerHopLimit and ignoreAsHops. See LineageFlags.
Set hops with an orFilters degree filter. Use values such as ["1", "2", "3+"]. The value "3+" covers three or more hops.
1. searchAcrossLineage
Fields on SearchAcrossLineageInput include urn, direction, types, query, start, count, orFilters, searchFlags and lineageFlags. The filters field is deprecated. Use orFilters. See SearchAcrossLineageInput.
Example: downstream lineage in a time range using lineageFlags
query searchAcrossLineage {
searchAcrossLineage(
input: {
urn: "urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)"
query: "*"
start: 0
count: 10
direction: DOWNSTREAM
orFilters: [
{ and: [{ field: "degree", condition: EQUAL, values: ["1"] }] }
]
lineageFlags: {
startTimeMillis: 1700000000000
endTimeMillis: 1705000000000
}
}
) {
searchResults {
entity {
urn
type
}
degree
}
}
}
2. scrollAcrossLineage
ScrollAcrossLineageInput has no start field. Page with scrollId in the input and nextScrollId in the result. See ScrollAcrossLineageInput.
Example: filtering with the direct fields
query scrollAcrossLineage {
scrollAcrossLineage(
input: {
urn: "urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)"
query: "*"
count: 10
direction: DOWNSTREAM
startTimeMillis: 1700000000000
endTimeMillis: 1705000000000
orFilters: [
{ and: [{ field: "degree", condition: EQUAL, values: ["1"] }] }
]
}
) {
searchResults {
entity {
urn
type
}
degree
}
}
}
Example: filtering with lineageFlags (recommended)
query scrollAcrossLineage {
scrollAcrossLineage(
input: {
urn: "urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)"
query: "*"
count: 10
direction: DOWNSTREAM
orFilters: [
{ and: [{ field: "degree", condition: EQUAL, values: ["1"] }] }
]
lineageFlags: {
startTimeMillis: 1700000000000
endTimeMillis: 1705000000000
}
}
) {
searchResults {
entity {
urn
type
}
degree
}
}
}
Additional Notes
- The direct
startTimeMillisandendTimeMillisfields are defined onSearchAcrossLineageInput. A "Field 'startTimeMillis' is not defined by type 'SearchAcrossLineageInput'" error is not expected on current DataHub Cloud. If you see it, check the query for typos and confirm you are sending it to the right endpoint. - Both time fields are optional. You do not need a time range to get lineage results.
- On DataHub Cloud, send the query to
https://<your-account>.acryl.io/api/graphqlwith the headerAuthorization: Bearer <token>.
Related Documentation
- GraphQL Input Objects: SearchAcrossLineageInput
- GraphQL Input Objects: ScrollAcrossLineageInput
- GraphQL Input Objects: LineageFlags
- Lineage API Tutorial
- GraphQL Best Practices
- DataHub Cloud GraphQL getting started
- Personal access tokens
Tags: api, lineage, graphql, searchAcrossLineage, scrollAcrossLineage, startTimeMillis, lineageFlags, time-filter