Today, i will discuss about the “Split Fields” component in Pentaho. Split Fields component split the value of a variable into multiple variables based on delimiter.For example, consider a variable var1 having value a;b;c. Now i need to split into three different values a,b and c. In order to achieve this, use split Fields component in Pentaho with delimiter as “;”. See the below image for the same.
Use Generate rows to generate one variable with value “a;b;c”. Then use the split Field component with delimiter as “;”. See the below image for the same. Use Write to log component to see the value of these variables var11,var12,var13.
Run the transformation , below output will appear on the screen.
Write to log.0 – ————> Linenr 1——————————
Write to log.0 – var11 = a
Write to log.0 – var12 = b
Write to log.0 – var13 = c
Here question that will definitely comes to everyone’s mind is what if the value is “a;b”. Now, execute the same transformation for var1=a;b. Below output will appear on the screen.
Write to log.0 – ————> Linenr 1——————————
Write to log.0 – var11 = a
Write to log.0 – var12 = b
Write to log.0 – var13 = null
This concludes that developer should be aware of maximum delimiter that will come in a value and accordingly define the variable names in split fields component.
Another scenario , consider the value of var1 is a;b;c;d . Run the transformation again. Below output will appear on the screen.
Write to log.0 – ————> Linenr 1——————————
Write to log.0 – var11 = a
Write to log.0 – var12 = b
Write to log.0 – var13 = c
Here, “d” is lost as split Fields component is having three variables. Did you observe one thing, transformation didn’t fail in case of any value that comes in var1.