Referencing previous row

Hi everybody,

sorry for touching this old thread, but I have the exact same problem and don't understand the solution @wiswedel wrote.
I'm using Knime 2.9.2 so perhaps something changed in the meantime.

Bernd wrote that it's possible to create costum class fields (class variables?) to store orevious values. I didn't get how this is possible.

As my System has enough memory I wanted to load the hole table into memory (or at least all values from selected columns).

i always tried to fix this problem with the "lag-column" node, but this time, i have to go back a value which is calculated during runtime.

i would be really happy if someone can help me with this problem!

Kind regards,
Stefan Kraus

Oh man, sorry now i got it.

 

you can declare, a class variable, and then fill it with content in each row.

so you can "look" backwards, but not forward. It's not quite as nice as i hoped, but with the right sorting its working for my case.

for people who have the same issue, here is a code example i used:

......
// Your custom variables:

int oldCostumer;

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

if(c_customerID == oldCostumer){

//do your things you want to do when costumerID is the same as the row above
}

//end
oldCostumer = c_customerID;

// expression end
    }
}

 

You can declare an array than can hold the values. The size of the array can be the no of rows you want to refer.

// system variables
public class JSnippet extends AbstractJSnippet {
  // Fields for input columns
/** Input column: "temperature" */
  public Double c_temperat;


// Your custom variables:
double[] temp_arr=new double[4];
int idx=0;
// expression start
  public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:

temp_arr[idx]=c_temperat;
idx=(idx+1)%temp_arr.length;

// expression end
    }
}