dynamic java snippet column name handling

Hello :),
I have a transpose node and a java snippet node between a Group loop start and loop end node. I performed a transpose in each loop to perform a computation in the java snippet, which means the column names keep changing. How do I dynamically handle column name changes? Each Group loop start has two rows. After transpose becomes two columns with different names always.
For example, the first group has Row1 and Row2…next have Row3 and Row4.

Hi @Arnold,
Is there always the same number of rows in one loop iteration? You could use the Column Rename (Regex) node with a static new name, e.g. “NEW”. Then your columns will be called “NEW”, “NEW (#1)”, “NEW (#2)” and so on. From there you can use a normal Column Rename to change the names to what you need. But of course this means they have to be always in the right order. Alternatively, if you have a column that contains the actual column names, you can use a RowID node to make that column’s value the row id and then transpose, so that the row id becomes the column name.
Kind regards
Alexander

1 Like

Hi @Arnold,
I think your question referred to the general usage of KNIME Analytics Platform, not development, so I moved it into the appropriate category. Please let me know if I misunderstood you in that regard.
Kind regards
Alexander

1 Like

@AlexanderFillbrunn unfortunately, none of the above work because transpose always make sure the two columns have unique column names even if they are renamed before hand.

Hi,
can’t you do the rename after the transpose?
Kind regards
Alexander

hello @AlexanderFillbrunn each group loop start…picks each time two different rows with different ids. and this stage is where the problem is. renaming here means knowing exact names or having a way to automate. so renaming after transpose wont work because the names keep changing even before transpose. because renaming has to know the names beforehand and these names keep updating in each loop.

Hi,
that’s why I suggested the Column Rename (Regex) node. It allows you to rename columns based on a pattern. By default, the pattern matches every column name, which is what we want here. If you specify a static string as the replacement name, KNIME will append a suffix with numbers. Now you have always the same column names in every iteration and can use the normal Column Rename node to give the columns names that you actually want.
Kind regards
Alexander

2 Likes

@AlexanderFillbrunn thank you very much. Column Rename (Regex) did the magic.

2 Likes

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