Area: API
Sub-Area: GraphQL
Applies to: OSS + Cloud
Issue
GraphQL queries to the DataHub API are slow, fail with a timeout, or are rejected for being too large or too deep. This usually happens when you page through large result sets with offset pagination, nest too many objects, or ask for more fields than you need.
Errors you may see:
-
maximum query depth exceeded <depth> > <limit>. The default depth limit is 50. -
maximum query complexity exceeded <complexity> > <limit>. The default complexity limit is 2010 in OSS v1.9.0 and 2100 in DataHub Cloud v2.4.4. - On DataHub Cloud v2.4.4, a server-side timeout. DataHub reports it with the GraphQL error code
DEADLINE_EXCEEDED, which maps to HTTP 504.
You Might Be Asking
- How do I page through large result sets?
- Why is my GraphQL query slow?
- Why do I get "maximum query depth exceeded" or "maximum query complexity exceeded"?
- What are best practices for DataHub GraphQL queries?
Cause
-
searchandsearchAcrossEntitiesare designed for shallow pagination (less than about 50 results deep). They can't page past 10,000 results. - Large
countvalues, many entity types and deeply nested selections make each request expensive. - Queries over the depth or complexity limit are rejected. These limits are server settings.
Solution
1. Use scroll pagination for large result sets
Use scrollAcrossEntities for deep or bulk paging. Sort by urn so the order is stable. Leave scrollId out on the first request. Then pass the returned nextScrollId as scrollId on the next request. nextScrollId is null when a page comes back short or empty, so loop until it is null. If the last page is exactly full, you get one more request that returns no results.
query scrollDatasets($scrollId: String) {
scrollAcrossEntities(
input: {
types: [DATASET]
query: "*"
count: 100
scrollId: $scrollId
sortInput: { sortCriteria: [{ field: "urn", sortOrder: ASCENDING }] }
}
) {
nextScrollId
count
total
searchResults {
entity {
urn
type
}
}
}
}
Notes:
-
queryis required.scrollAcrossEntitieshas nostartfield and nofiltersfield. Sending either one fails validation. - If you do use offset paging with
search, stop whenstartis greater than or equal tototal. - Page size: with minimal fields, a page can return 1,000 to 2,000 results. For complex requests with many nested objects, lower
countto 20 to 25.
See Deep Pagination: search* vs scroll* APIs.
2. Select type-specific fields inside inline fragments
searchResults { entity } returns the Entity interface. It only has urn, type and relationships. Put every other field, such as name, inside an inline fragment.
searchResults {
entity {
urn
... on Dataset {
name
}
}
}
Selecting name directly on entity fails validation.
3. Filter with orFilters and URN values
Use orFilters. The older filters field on search is deprecated. The platform field holds a data platform URN, so use the full URN. Not every filter field is URN-based: origin (Environment) takes values such as PROD.
query {
search(
input: {
type: DATASET
query: "sales"
orFilters: [
{
and: [
{ field: "platform", values: ["urn:li:dataPlatform:snowflake"] }
{ field: "origin", values: ["PROD"] }
]
}
]
start: 0
count: 50
}
) {
start
count
total
searchResults {
entity {
urn
... on Dataset {
name
}
}
}
}
}
Criteria inside one and list are ANDed. Separate entries in orFilters are ORed. See the Search guide.
4. Read lineage with the lineage queries
Dataset has no upstreamLineage or downstreamLineage GraphQL field. DataHub docs recommend the searchAcrossLineage and scrollAcrossLineage root queries for lineage, including depth greater than 1 through the degree filter. Dataset also has lineage(input: LineageInput!).
See the Search Across Lineage section of the GraphQL best practices page.
5. Request only the fields and entity types you need
List only the entity types you need in types. Select only the fields you use. Fewer nested objects keep you under the depth and complexity limits.
6. Fetch several known entities in one request
Use entities(urns: [String!]!) instead of many separate lookups. It returns Entity, so use inline fragments for type-specific fields.
query batchGet {
entities(urns: ["urn:li:dataset:(...)", "urn:li:dataset:(...)"]) {
urn
... on Dataset {
name
}
}
}
Leave checkForExistence unset unless you need it. Setting it to true makes n+1 SQL calls.
If the limits still block you
The depth limit and complexity limit are GMS server settings (GRAPHQL_QUERY_DEPTH_LIMIT, GRAPHQL_QUERY_COMPLEXITY_LIMIT). The maximum result count is also a GMS setting (SEARCH_SERVICE_LIMIT_RESULTS_MAX). Its default is 10000 in DataHub Cloud v2.4.4.
- On self-hosted DataHub, an administrator sets these in the GMS configuration.
- On DataHub Cloud, contact DataHub Support about these settings.