Page 1 of 1

String to Decimal Validation

Posted: Tue Aug 07, 2012 8:33 am
by SettValleyConsulting
In a transformer, fitted with a reject link, I am mapping a string to a decimal type.

What I want to happen:-

If the incoming data is not a numeric string, e.g. 'aaaa' I want the row to be shunted into the reject link.

What actually happens (to my surprise)

The value is defaulted to zero, a warning is issued to the log, however the row continues on its merry way.

Is there any way of making the transformer behave the way I want? Or do I have to code up a validation for each and every decimal?

Posted: Tue Aug 07, 2012 9:07 am
by ArndW
Unfortunately, I would say that you would need to code up a "IsValid()" for each of those conversions.

Posted: Tue Aug 07, 2012 9:12 am
by SettValleyConsulting
Thank, Arnd. I'd pretty much come to the same conclusion, just wondering if there was some obscure option to switch on strong typing .....

Posted: Tue Aug 07, 2012 9:23 am
by ArndW
If all of the decimals have the same behaviour plus your source is a sequential stage, you could do the conversion from string to decimal implicitly when reading the data and then specify handling for decimals in the stage attributes.

Posted: Tue Aug 07, 2012 9:26 am
by ShaneMuir
Just for my understanding does that mean that the output row has to fail before its written to an reject link? eg trying to convert something for which there is no conversion.

And since the value here would be defaulting during its conversion that is not a failure hence no reject?

Posted: Tue Aug 07, 2012 2:51 pm
by FranklinE
String function Num() confirms that the string can be converted to a number. It is available in the Transformer constraints. The Otherwise/log function looks promising, Parallel Job Developer's Guide (7.x) page 16-17.

Posted: Wed Aug 08, 2012 1:47 am
by ShaneMuir
Hi Franklin

I think that is what Phil was trying to avoid - ie having a validation check for the field (whether it be IsValid() or Num()).

By having the conversion from string to decimal, and a reject link, it was hoped that when the conversion encountered a non numeric value that this would 'fail' and be sent down the reject link, removing the need to code a validation check. My understanding is that what actually happened is that the conversion from string to decimal has merely replaced a non numeric value with a default value of 0 and continued on its merry way.