Merge Variables Node (Inactive Brach)

Hi friends,
I’m trying to apply the “Case Switch node” in an operation with a Group Loop.
But my problem isn’t with them.

My issue is that I’m creating the file name dynamically.

Explanation:

In the Case Switch Node:

  1. If Branch 1 is active, a specific file name will be created.
  2. If Branch 2 is active, a Group Loop will start to “split the file into 3 parts,” and a dynamic file name will be created for the 3 files.

I’m using only one CSV Writer,
so I need to use the Merge Variables node to combine both options.

My problem is that the Merge Variables node doesn’t accept connecting a variable with 1 inactive branch (screenshot 2).

My goal was that regardless of the chosen branch, I would pass the file name variable.

(I think I should use some kind of Try-Catch so that after the inactive branch, I can force a valid variable.)

My question is: How could I solve this situation? Which node could I use to pass a valid result at this point of the inactive branch? (screenshot 3)

(Honestly, I don’t know if this is the best strategy for the workflow, but it’s what I have at the moment.)

(main workflow)

(screen shot 2)

(screen shot 3) Brach Inative (string to path)

I’m trying to change the workflow structure…
(Maybe not the right way) Two hours racking my brain.

I have tried two different types with no succes.

Coming back soon for my new approach

Ok Ok…

I made several attempts, and my issue always occurred during the finalization of the Group Loop/End Loop.

I kept looking at the workflow, thinking, and my decision was as follows:

  1. Inside the Case Switch, I identified the rule I set: If the total number of rows is greater than 300,000, then branch 2; otherwise, branch 1. In the Column Expression, I created a column as a string to identify which result was selected.

    image

image

  1. Then, I used a Row Splitter to separate branch 1 in Port 1 and branch 2 in Port 2.

  2. After that, I followed the rules to create files for each branch. For branch 2, I split the table into three parts (since the file is too large to open in Excel). The main idea is to split only when necessary.

The expected result worked, but my loop ends up creating empty files when passing through the nodes, though it eventually generates the correct files.

3 files result and some “erros files missing”
image

To solve this problem, I’ll set a new rule to delete files containing the word “missing.” I think this is easier than adjusting the workflow and getting lost again.

Resume
My initial attempt was to use just one CSV Writer, but when I split the file into three, the file name changes slightly because I need to identify the iteration, number of rows per file, etc.

Either way, I believe the method I used is still not the best. I’m sure there must be a better approach.

I still don’t understand how the Try-Catch works. I tried looking at some examples, but it’s still unclear to me how to handle errors properly. I’ll need to dive deeper because I see it’s a frequently used node, and I really haven’t grasped it yet.

I left this explanation for future “Knimers.”

Thanks!

2 Likes

@Felipereis50 great that you found a solution. With knime often there is more than one. Also very good that you wrote about your solution so others could learn.

With loops and switches it will involve some planning and to think about what should happen as an alternative. Things that are used in both (or more) paths should be done before or outside a loop or switch.

Then one should think about the collection of the results.

And the first iteration of a loop can be different to set the stage so to speak.

In general if you discuss a problem on the forum it can help to provide an example that tries to isolate and pin down the core challenge. Once that is solved it can be integrated in your work and can provide solutions for others.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.