Traverse categories¶
You can populate glossaries in Atlan with arbitrarily deep category hierarchies.
graph
g([Glossary])
c1([Category 1])
c2([Category 2])
c1a([Category 1a])
c1b([Category 1b])
c1ai(["Category 1a(i)"])
c1aii(["Category 1a(ii)"])
tA([Term A])
tB([Term B])
g-->c1-->c1a
g-->c2
c1-->c1b
c1a-->c1ai
c1a-->c1aii
c1b-->tB
c1ai-->tA
To traverse these categories efficiently (without retrieving each level through a separate API call) you need to search for all categories in a glossary and reconstruct the hierarchy in-memory. This reconstruction can be cumbersome, so we've provided a helper method for that in the SDKs.
Retrieve the hierarchy¶
To retrieve a traversable hierarchy for a glossary:
Retrieve traversable hierarchy | |
---|---|
1 2 |
|
- Start by retrieving the glossary itself, for example using
Glossary.findByName()
. The glossary object used must have itsqualifiedName
present, so if you already know thequalifiedName
you could also useGlossary._internal().qualifiedName("...").build();
as a shortcut, which does not require making any API call. - Call the
.getHierarchy()
method on the glossary to retrieve a traversableGlossary.CategoryHierarchy
object.
More details
The .getHierarchy()
method will only retrieve the bare minimum information about each category (its GUID, qualifiedName and name). If you want to retrieve additional details, such as the terms in that category or certificate for the category, you need to pass these as an additional argument. To do this, use the .getHierarchy(List<String>)
method, and pass a list of strings giving the names of any additional attributes you want to retrieve for each category. (For example, to retrieve terms you would use terms
, for certificates you would use certificateStatus
.)
Retrieve traversable hierarchy | |
---|---|
1 2 3 4 5 |
|
- Start by retrieving the glossary itself, for example using
find_glossary_by_name()
. The glossary object used must have itsqualified_name
present. - Call the
get_hierarchy()
to retrieve a traversableAtlasGlossary.CategoryHierarchy
object.
More details
The .get_hierarchy()
method will only retrieve the bare minimum information about each category (its GUID, qualifiedName and name). If you want to retrieve additional details, such as the terms in that category or certificate for the category, you need to pass these as an additional argument. To do this, add the additional attributes
parameter and pass a list of strings giving the names of any additional attributes ou want to retrieve for each category. (For example, to retrieve terms you would use terms
, for certificates you would use certificateStatus
.)
Retrieve traversable hierarchy | |
---|---|
1 2 |
|
- Start by retrieving the glossary itself, for example using
Glossary.findByName()
. The glossary object used must have itsqualifiedName
present, so if you already know thequalifiedName
you could also useGlossary._internal().qualifiedName("...").build();
as a shortcut, which does not require making any API call. - Use the
.hierarchy
member on the glossary to retrieve a traversableGlossary.CategoryHierarchy
object.
More details
The .hierarchy
member will only retrieve the bare minimum information about each category (its GUID, qualifiedName and name). If you want to retrieve additional details, such as the terms in that category or certificate for the category, you need to pass these as an additional argument. To do this, use the .getHierarchy(List<String>)
method, and pass a list of strings giving the names of any additional attributes you want to retrieve for each category. (For example, to retrieve terms you would use terms
, for certificates you would use certificateStatus
.)
Requires multiple API operations and non-API logic
To retrieve all categories in a glossary could require multiple API operations, to page through results. You would do this by incrementing the from
in each subsequent call (in increments equal to the size
) to get the next page of results.
Each page of results from the search will return a flat list of categories. You will need to use the parentCategory
relationship within each result to reverse-engineer the hierarchical structure of the categories from the flat lists.
POST /api/meta/search/indexsearch | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
- You should run a search to efficiently retrieve many categories at the same time.
- Use the
from
parameter to define the start of each page. If you have many categories in the glossary, page through them rather than trying to retrieve them all in a single request. Thefrom
should be incremented in multiples of thesize
, so in this example would be0
,20
,40
, and so on. - The
size
parameter controls how many categories you will try to retrieve per search request. - You will probably want to filter the categories to only those that are active (excluding any archived or soft-deleted categories).
- You should filter the search by a specific type, in this example
AtlasGlossaryCategory
is the name of the type in Atlan for categories. -
Finally, you should also filter the search for the specific glossary in which to find the categories.
Requires qualifiedName of the glossary
Note that this requires the `qualifiedName of the glossary, which therefore must first be known or found by an earlier search on glossaries.
-
When you expect to page through results, it is always a good idea to sort the results so that each page returns them in a consistent order.
- Since we want to be able to understand the hierarchy of categories, we also need to include the
parentCategory
in each result.
Traverse the hierarchy¶
To traverse the hierarchy of categories you then have a few options.
Depth-first traversal¶
To list every category in the hierarchy in depth-first order:
Traverse the hierarchy depth-first | |
---|---|
3 4 5 6 7 |
|
- The
.depthFirst()
method will return an ordered list of all the categories in the glossary, ordered by a depth-first traversal. - You can then iterate through them in this particular order.
Traverse the hierarchy depth-first | |
---|---|
6 7 8 |
|
- The
depth_first
property will return an ordered list of all the categories in the glossary, ordered by a depth-first traversal. You can then iterate through them in this particular order.
Traverse the hierarchy depth-first | |
---|---|
3 4 5 6 7 |
|
- The
.depthFirst()
method will return an ordered list of all the categories in the glossary, ordered by a depth-first traversal. - You can then iterate through them in this particular order.
Non-API logic
Once you have retrieved the categories using the search approach outlined above, traversing them becomes an operation entirely in your own program (does not interact with Atlan APIs).
For a depth-first traversal:
- Start by listing a single top-level category (those whose
parentCategory
relationship is empty). - Then output a single child category of that top-level category.
- Then output a single child category of (2).
- Continue in this way down the hierarchy.
- Once exhausted, then move on to the next (grand-)child category and exhaust its (grand-)children.
- Continue in this way until all categories are listed.
Breadth-first traversal¶
To list every category in the hierarchy in breadth-first order:
Traverse the hierarchy breadth-first | |
---|---|
3 4 5 6 7 |
|
- The
.breadthFirst()
method will return an ordered list of all the categories in the glossary, ordered by a breadth-first traversal. - You can then iterate through them in this particular order.
Traverse the hierarchy breadth-first | |
---|---|
6 7 8 |
|
- The
breadth-first
property will return an ordered list of all the categories in the glossary, ordered by a depth-first traversal. You can then iterate through them in this particular order.
Traverse the hierarchy breadth-first | |
---|---|
3 4 5 6 7 |
|
- The
.breadthFirst()
method will return an ordered list of all the categories in the glossary, ordered by a breadth-first traversal. - You can then iterate through them in this particular order.
Non-API logic
Once you have retrieved the categories using the search approach outlined above, traversing them becomes an operation entirely in your own program (does not interact with Atlan APIs).
For a breadth-first traversal:
- Start by listing the top-level categories (those whose
parentCategory
relationship is empty). - For each of these categories, then list all of its children.
- Continue the logic from (1) for each child category.
Build-your-own traversal¶
Alternatively, you may want to iterate through the hierarchy in your own order. From the traversable hierarchy you can retrieve the top-level categories, and then decide what to do from there:
Traverse the hierarchy as you like, starting from the top | |
---|---|
3 4 5 6 7 8 9 10 11 12 |
|
- The
.getRootCategories()
method will return a list of only those categories at the root of the glossary. (The categories that have no parent categories themselves.) - You can then retrieve the child categories using
.getChildrenCategories()
. And you can do this iteratively as you traverse down the hierarchy.
Traverse the hierarchy as you like, starting from the top | |
---|---|
6 7 8 9 10 |
|
- The
root_categories
property will return a list of only those categories at the root of the glossary. (The categories that have no parent categories themselves.) - You can then retrieve the child categories using
children_categories
property. And you can do this iteratively as you traverse down the hierarchy.
Traverse the hierarchy as you like, starting from the top | |
---|---|
3 4 5 6 7 8 9 10 11 12 |
|
- The
.rootCategories
member will return a list of only those categories at the root of the glossary. (The categories that have no parent categories themselves.) - You can then retrieve the child categories using
.childrenCategories
. And you can do this iteratively as you traverse down the hierarchy.
Non-API logic
Once you have retrieved the categories using the search approach outlined above, traversing them becomes an operation entirely in your own program (does not interact with Atlan APIs).