The most basic and common ways of filtering are done with the following steps:
not (a "reversed filter")
has (can check if a field exists and if a field has a specific value)
hasNot (check if a field does not exist)
hasLabel (check the component/reference type)
is (to check if a value matches)
Here's an example that tries to use all the filters at once to find components that
does not have a
does have an owner (via the
has more than two references
do not realize a Business Capability (via the
Is Realized By-reference)
not(__.in('Is Realized By').hasLabel('Business Capability'))
Advanced Filtering Using "Where"
The filter options seen above takes care of most use-cases, but you'll notice that none of these filters compare values from one part of the graph traversal against the value from another part of the traversal.
For example, how would we see if there are two directly connected components with the same
Lifecycle Phase? This is when the where-step becomes useful:
Explaining the Parts ("as" and "by")
For the where-step to do its job, we need to add some aliases to the entities found during the graph traversal. This is done using the as-step.
In our example, we create a traversal that starts by finding all components that have a
lifecycle_phase, and then give them the alias
Then, we find all incoming and outgoing references (to ensures they are included in the path), that connect to a component that also has a
Lifecycle Phase. We give this other component the alias
Now that we have two aliases, we can use
where to see if
"lp2". However, this means that we are comparing two components, which will never be the same (so we get zero results)!
This is where the "by-step" comes in, which lets us modulate the where-statement to instead use a different value for the comparison. We write
by('lifecycle_phase') which tells Gremlin that it should compare the
Lifecycle Phase field for these two components instead of comparing them in their entirety. Since we are comparing the same field on both components we may use only one by-step, but if you want to compare two different fields, just add two by-steps, for example:
More Advanced By-step Modulation
The by-step used in the where-filter can be very powerful! For example, what if we simply want to find all components that are connected to at least one component that has a similar
Lifecycle Phase? In that case, we don't even need to create a traversal beforehand, we can just create two aliases for the same component and perform the traversal in the by-modulation. Note that since we now compare a list of referenced components, we need to use "
within" instead of "
fold the referenced components' lifecycle phases together into a list:
Find all components that have a second-degree reference to themselves
Find all components that do not have a second-degree reference to themselves
Still have questions? Feel free to reach out to us via the in-app chat or our website.