cancel
Showing results for 
Search instead for 
Did you mean: 

Which pattern for recursive/DFS traversal of tree?

mnyolt
New Contributor

I’m quite new to SnapLogic and struggling to create a pipeline which traverses a tree structure.

The use-case is that as an input, I get a tree-structure of items, and want to replicate this in another system.
For creating sub-items, I first need to create the parent item and specify its Id (within the target system) during the create of the sub-items. Thus a DFS traversal is essential.

I tried to implement a basic traversal like this:

image

The JSON Generator creates a simple test document:

[
    {
        "a": 0,
        "children": [
            { "a": 1 }
        ]
    }
]

The splitter reads the children property and feeds the children back to the union.
The union serves as the “loop” and combines the original document with any nested child documents.
The filter is configured with $.get('children') != null and ensures that the splitter does not create empty documents.

The logic of the pipeline should be sound, since at some point no children are left, and no more documents are created by the splitter.
But I get an StackOverflowError.
(Which surprises me, since outputViews just write and inputViews just poll - if connected properly, no infinite recursion should happen - it’s basically just streams connected, right?)

It seems this is not the way to traverse such a tree structure.
I also read that recursive pipeline execution is not supported.

So, what is the usual pattern of traversing such a tree structure recursively in a DFS manner?

0 REPLIES 0