Customer Portal

Creating a Hierarchy Tranformation

Comments 1

  • Avatar
    imriskal
    0
    Comment actions Permalink
    Hi, skylaneffz,

    if your input file is the same as you posted, i.e. always sorted by CHILD_ID and the numbers from the root to leaves are always sorted in ascending order (e.g. 2000 can not be a parent of 1500), you can use a Reformat component with the following CTL code.
    //#CTL2

    map[string, string] childParent;

    function integer transform() {
    string res = $in.0.CHILD_ID;
    childParent[res] = $in.0.PARENT_ID;
    string act = $in.0.CHILD_ID;

    while (childParent.containsKey(act)) {
    act = childParent[act];
    res = act+"|"+res;
    }

    $out.0.path = res;
    return OK;
    }

    If your input file was somehow different, you should save the input records into the lookup table first and only then you can use similar approach.

    Best regards,

Please sign in to leave a comment.