Getting content of a specific row in each iteration of a loop

Hello everyone,

I'm really new to KNIME and I want to write my own Java Snippet. In there I want to iterate over the rows of one column of the input table. In each iteration I want to use the content of the actual row. That means: When the iteration variable is 4, I want to work with the content of row 4 in the specific column.

Is there something like getCell(ColumnName, tInt) [4]; (4 for the fourth row)?

I hope you get, what I mean and can help me.

Thank you very much.

KNIME-Learner

In the Java snippet node your code is run on a single line (1 by 1) so it already does what you want. 

Hello swebb,

thank you very much. I haven't known that. So I updated my code, but now I have a problem with the following expression:
out_xx = getCell(c_Clusternumber, tInt);

By using this line of code I want to read the Integer content of the actually regarded cell. My input table has 18 rows and I get similar warnings for each row except of row 14.

The warning looks like this:
WARN JavaSnippetCellFactory Evaluation of java snippet failed for row "Row18". The exception is caused by line 32 of the snippet. Exception message:Index: 2, Size: 1

Line 32 is the line with the getCell() method. The index value in the warnings is decreasing from 18 to 2 and the size value is always 1.

My code now looks like this:

// system variables
public class JSnippet extends AbstractJSnippet {
  // Fields for input columns
/** Input column: "Cluster number" */
  public Integer c_Clusternumber;

  // Fields for output columns
/** Output column: "max" */
  public Integer out_max;

// Your custom variables:

int p = ROWCOUNT-1;
int max = 0;

// expression start
  public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:

int temp = getCell(c_Clusternumber, tInt);

 if (temp>max) {max=temp;}
 else {};

out_max = max;

// expression end
    }
}

Hopefully, somebody can tell me my fault.

KNIME-Learner

can you upload the workflow? It would make taking a look easier. 

Hello swebb,

unfortunately I cannot upload the workflow, because it is a workflow of the company I'm working for.

But I can describe the input data and the output data and then you might rebuild the neccessary nodes of the workflow.

So the input for the java snippet is a table with 34 columns and a variable amount of rows (depends on the result of other nodes). One of the columns is called "Cluster number". It contains increasing numbers starting at 0. Each number can appear more than once.

The goal of the java snippet is to find the hifghest number in the snippet and to put this number into a flow variable, that can be passed on to a Counting Loop Start node.

I already got a kind of workaround with existing KNIME nodes, but I would like to use a single Java Snippet.

If somebody can solve the problem and post a node or the source code of the node, I wuold be happy.

KNIME-Learner

Ok, I was able to aolve the problem.

The solution of the problem is this:
Changing
int temp = getCell(c_Clusternumber, tInt);
to
int temp = c_Clusternumber;

Thank you for your help, swebb.

KNIME-Learner

Glad you got it fixed, I was trying to work out while you were calling getCell() and not just assigning the variable. 

Yes, my fokus was fixed on this method, because I'm new to KNIME and the description of the method has seemed to describe exactely what I wanted. So, it took a long time to realize, that I do not even need this method.

Again: Thank you for your help. :-)

KNIME-Learner