root function

The root function returns the corresponding root of a node. The root is the very first node of the branch.


Parameters

root(parent, son, group, whichpath, separator, weights, operator)

Parameter

Description

parent

The attribute containing the parent nodes of a directed graph. The parent parameter is mandatory.

son

The attribute containing the son nodes of a directed graph. The son parameter is mandatory.

group

The attribute by which you want to further group results.

The group parameter can also be defined as a list: root($"parent",$"son",($"group1", $"group2"))

whichpath

When defined, it allows the user to choose which path is to be considered:

  • the shortest one - whichpath = "minimum",

  • the longest one - whichpath ="maximum" or

  • all the paths - whichpath = "all" - in this case, roots are concatenated in a single string.

If no path is specified, the root function applies the “minimum” variable by default.

separator

It specifies the separator to use in the concatenation of different roots.

The default separator is "-"

This parameter can only be used when the whichpath = "all" is defined.

weights

The attribute defining the length of the edge.

operator

It defines how to combine weights attributes along the path to the root.

If left unspecified, the default operator applied is sum and the weight attributes will be summed. While if the operator is prod, they will be multiplied.

It can only be used if the weights parameter is specified.


Example - root(parent,son)

The following example uses the BOMs dataset.

Description

Screenshot

In this example, we want to retrieve the corresponding root of the nodes defined in the son attribute.

In the root function, we need to define which attribute is the parent, and which is the son. This is a Bill of Material (BOM), and the parent-son relationship is defined respectively by the ParentComponentID and ComponentID attributes.

So, the formula is: root($"ParentComponentID",$"ComponentID")

Here we can see the results - the root function has retrieved the root for each son node.


Example - root(parent,son,group)

The following example uses the BOMs dataset.

Description

Screenshot

In this other example, we want to retrieve the root of the nodes defined in the son attribute, and group the results by the Quantity attribute.

We’re still using the BOM dataset, so the parent-son relationship is respectively defined by the ParentComponentID and ComponentID.

So, the consequent formula would be: root($"ParentComponentID", $"ComponentID", $"Quantity")

Here are the results that have been grouped by the Quantity attribute.