I have many fields all needing the same recoding, is there a transformation that will allow me to specify all the fields requiring the same mapping, rather that having to create a Value Mapper transformation for each field? I am using Kettle Spoon 4.4
I am not a huge fan of Java Scripting on Kettle, but I don't know of any other standard step that does what you wish.
You can add a Modified Java Script step to your stream and write a simple code to map the values of a list of fields (columns). To accomplish this, suppose you have fields A
and B
both with two possible values S
for small and B
for big. To map them you should insert the following javascript code:
// list of fields you wish to map
var fieldsToMap = ["A", "B"];
var tmpField;
var fieldIndex;
// for each field to map...
for (var i=0; i < fieldsToMap.length; i++) {
//get the index of the field once you only have it's name
fieldIndex = getInputRowMeta().indexOfValue(fieldsToMap[i]);
//get the field
tmpField = row.getValue(fieldIndex);
//don't forget to trim as Kettle usually pads strings
switch (trim(tmpField)) {
case "S":
tmpField.setValue("Small");
break;
case "B":
tmpField.setValue("Big");
break;
}
}
Don't forget to check Compatibility mode?
at the Java Script step, otherwise you'll have a javascript error once with the new standards you are not allowed to change a field value any more (see How to modify values (with compatibility off) at http://wiki.pentaho.com/display/EAI/Modified+Java+Script+Value)