root function in the Factory
The root function returns the corresponding root of a node. The root is the very first node of the branch.
Parameters 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: whichpath When defined, it allows the user to choose which path is to be considered: the shortest one - the longest one - all the paths - 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 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: 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: Here are the results that have been grouped by the Quantity attribute. root(parent, son, group, whichpath, separator, weights, operator)
root($"parent",$"son",($"group1", $"group2"))
whichpath = "minimum"
,whichpath ="maximum"
orwhichpath = "all"
- in this case, roots are concatenated in a single string."-"
whichpath = "all"
is defined.root($"ParentComponentID",$"ComponentID")
root($"ParentComponentID", $"ComponentID", $"Quantity")