Hello! Can someone point me to Graph Ql references...
# getting-started
c
Hello! Can someone point me to Graph Ql references/guide to query Business Glossaries ?
1
a
I would use the
searchAcrossEntities
and provide the type GLOSSARY_TERM. I would then loop over the list of urns and retrieve details with a call to
glossaryTerm
. Something like this:
Copy code
query {
    searchAcrossEntities(input: {
        start: 0,
        count: 100,
        query: "",
        types: [GLOSSARY_TERM]
    }
    ) {
        searchResults {
            entity {
                urn,
                __typename
            }
        }
    }
}
Then do:
Copy code
query($urn: String!) {
    glossaryTerm (urn: $urn) {
        properties {
            name
        }
    }
}
You can also make the search more specific, by providing additional parameters like filters for example. See the documentation for more information.
c
Thank you! Can you help me with sample for the same scenario for Python SDK and OPEN API ?
c
Thank you, However, I need help with sample code to query the Business Glossary Terms using Python SDK and OPEN API. I am trying to create a POC to provide options to developers to consume the Terms programmatically. Your first response covers the Graph QL and I need the same with Python SDK and OPEN API. 1. Query all the Business Glossary Terms. 2. Get the parent nodes of the terms 3. Filter with an individual term or term group Hope this makes sense. Thanks in advance.
a
My last response shows you an example of how to put the queries I wrote in the first response in Python the same way the DataHub product does. I must have misunderstood your question... What do you mean by Python SDK and what do you mean by OPEN API? Could you provide a link for me to understand your question better?
c
We are exploring on options to query the business glossary in different ways. 1 way is Graph QL, for which you have provided the solution. The other 2 ways I am trying to explore is 1. Using Python SDK ( REST Emitter) 2. OPEN API( CURL commands or Postman) I installed the Python Emitter
pip install -U 'acryl-datahub[datahub-rest]'
and tried this code using the rest emitter library -
Copy code
from datahub.emitter.rest_emitter import DatahubRestEmitter
from datahub.metadata.schema_classes import GlobalSettingsInfoClass
# Create rest emitter
rest_emitter = DatahubRestEmitter(gms_server="<http://localhost:8080>")

# Fetch all glossary terms
glossary_terms = rest_emitter.get_glossary_terms()

# Print the glossary terms
for term in glossary_terms:
    term_urn = term.entityUrn
    term_name = term.aspect.name
    term_definition = term.aspect.definition
    print(f"Term URN: {term_urn}")
    print(f"Term Name: {term_name}")
    print(f"Term Definition: {term_definition}")
    print("---")
The process failed with below error -
glossary_terms = rest_emitter.get_glossary_terms()
AttributeError: 'DataHubRestEmitter' object has no attribute 'get_glossary_terms'
I need your help with sample code that I can use to fetch the business glossaries both via Python Emitter and OPEN API ( CURL and Postman)
@acceptable-morning-73148 - Any help?
a
Hello @calm-agency-11588, now that I started writing an example I came to the conclusion that you can retrieve this in one go like this:
Copy code
from datahub.ingestion.graph.client import DataHubGraph, DataHubGraphConfig

datahub_graph = DataHubGraph(DataHubGraphConfig(server="<http://localhost:8080>"))


def get_business_glossary_terms():
    graphQl = """
        {
            searchAcrossEntities(
                input: {start: 0, count: 100, query: "", types: [GLOSSARY_TERM]}
            ) {
                searchResults {
                    entity {
                        urn
                        ... on GlossaryTerm {
                            properties {
                                name
                            }
                        }
                    }
                }
            }
        }
    """
    result = datahub_graph.execute_graphql(graphQl)
    return map(
        lambda x: x["entity"]["properties"]["name"],
        result["searchAcrossEntities"]["searchResults"],
    )


print(list(get_business_glossary_terms()))
c
Thank you @acceptable-morning-73148 - I am trying to get output in a json format with the nodes and terms in a hierarchical format. E.g: Parent node --> node 1 --> term1, term2 --> node 2 --> Term1 , Term2 … Thanks in advance!
a
You can take it from here, @calm-agency-11588. My last tip is to use the visual capabilities of Postman to create a GraphQL query the way you like it. For example something like this:
c
Hi @acceptable-morning-73148 - Thanks for the postman tip. I was able to construct the graph ql query to get all the business glossary terms in a hierarchical format. May be this can help you with any similar future enquiries
{
glossaryNode(urn: “urnliglossaryNode:<id>“) { urn
type
exists
properties {
name
description
}
ownership {
...ownershipFields
}
parentNodes {
...parentNodesFields
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total relationships { direction entity {
type
urn
... *on* GlossaryNode {
...glossaryNode } ...
*on* GlossaryTerm {
...childGlossaryTerm } } } } } }
*fragment* ownershipFields *on* Ownership {
owners { owner { ...
*on* CorpUser {
urn
type
username
info {
active
displayName
title
email
}
properties {
active
displayName
title
email
}
}
... *on* CorpGroup {
urn
type
name
properties {
displayName
email
}
info {
displayName
email
admins {
urn
username
info {
active
displayName
title
email
}
}
members {
urn
username
info {
active
displayName
title
email
}
}
}
}
}
type
associatedUrn
}
lastModified {
time
}
}
*fragment* parentNodesFields *on* ParentNodesResult {
count nodes { urn
type
properties {
name
}
}
}
*fragment* glossaryNode *on* GlossaryNode {
urn
type
properties {
name
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total __typename relationships { direction entity {
type
urn
... *on* GlossaryNode {
urn
type
properties {
name
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total __typename relationships { direction entity {
type
urn
... *on* GlossaryNode {
urn
type
properties {
name
__typename
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total __typename relationships { direction entity {
type
urn
... *on* GlossaryNode {
urn
type
properties {
name
__typename
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total relationships { direction entity {
type
urn
... *on* GlossaryNode {
urn
type
properties {
name
}
children: relationships(
*input*: {types: ["IsPartOf"], direction: INCOMING, start: 0, count: 10000}
) { total __typename relationships { direction entity {
type
urn
... *on* GlossaryNode {
__typename } ...
*on* GlossaryTerm {
...childGlossaryTerm __typename } __typename } __typename } } __typename __typename } ...
*on* GlossaryTerm {
...childGlossaryTerm __typename } __typename } __typename } } __typename __typename } ...
*on* GlossaryTerm {
...childGlossaryTerm __typename } __typename } __typename } } __typename __typename } ...
*on* GlossaryTerm {
...childGlossaryTerm __typename } __typename } __typename } } __typename } ...
*on* GlossaryTerm {
...childGlossaryTerm __typename } __typename } __typename } } __typename }
*fragment* childGlossaryTerm *on* GlossaryTerm {
urn
type
name
hierarchicalName
properties {
name
__typename
}
institutionalMemory{
elements
{
label
url
}
}
__typename
}
a
Thanks for sharing!