Replacing cell value with Flow Variable in a Java snippet

Hi everybody,

I am currently trying to optimize my workflow a bit.

Right now I am using a Column Expressions Node to replace a cell value in a column “Volume” with a flow variable called volume (this flow variable changes inside a parameter optimization loop).

To define the cell that is being replaced in the current parameter optimization loop, I use the iteration of an outer loop I am doing (so the first outer loop switches the value in the first row, the second outer loop changes the Volume value in the second and so on).

This is the code I am using inside the Column Expression Node right now, the node is set up to replace the column Volume:

if (rowIndex()== variable("IterationOuterLoop"))
    {  
    variable("Volume")  
    }
else
    {
    column("Volume")
    }

And this is the part of the current workflow, the values get changed in the Column Expression Node, I then calcuate a difference to target and that is being outputted to the parameter optimization loop end.

image

Now I recently found out that a Column Expression is a pretty slow way of doing something like this (Any plans to speed up Column Expression node? - #2 by andres_sommerh).
So now I want to take a speedier approach to things by replacing the Column expression node with a Java snippet or any other faster way.

The point is that i do not know how to write the javacode for something like this. And it would be fantastic if some of you guys could help me with it :slight_smile:

I attached some sample data below:
ReplacingValues.xlsx (4.0 KB)

Best regards and thank you all!
Timo

Hello @TimoW,

I would go with Rule Engine node. Something like this:

ROWINDEX = iterationVariable => volumneVariable
TRUE => volumneColumn

Br,
Ivan

2 Likes

Hi @ipazin

and i thought i have to throw around some java code… That works incredibly well!
Thank you for the fast help :slight_smile:

Best regards
Timo

1 Like

Can you give an indication about performance difference? That would be very interesting to me.

1 Like

Hi @Daniel_Weikert ,

sorry for the late response, sure, i exported some timer info on the different approaches and converted it to seconds.

These are the three main components that run in the workflow, the rest are just single Nodes that do not impact performance.
Honestly I cannot tell you why it works so much quicker, these three components contained a single column expression each. Changing these three nodes to a rule engine gave me an 88% boost in execution time without changing anything else.

IT’s important to note that each of these column expressions / rule engines run in a nested loop, so they are executed a couple of hundred to thousand times everytime the workflow runs.

Best regards
Timo

2 Likes

Hello,

here is a bit of explanation about execution difference between Column Expressions vs Rule Engine:

Br,
Ivan

1 Like

Thanks @ipazin thats a really good info you got there!

Best regards
Timo

1 Like

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