Newbie 'Replace' Question

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

daveinhants
Posts: 4
Joined: Wed Aug 12, 2015 11:14 pm

Newbie 'Replace' Question

Postby daveinhants » Wed Aug 12, 2015 11:28 pm

I'm a total newbie only starting to use the tool yesterday!

I have a simple CSV input file where I want to replace the values in one column with a different value. The field currently contains values such as "Y", "N", "NA", blanks etc. I want to replace these with "XXX", "YYY", "ZZZ" etc.

I have used the Reformat Transformer to apply replace($in.0.Part,"Y","XXX") but I just get an error. The field is a string.

The source code looks like this $out.0.Part = replace($in.0.Part,"Y","XXX");

I have applied the same syntax to another field which is also a string and it works..... replacing "-" with "/" for example.

I can't see what I'm doing wrong.... any advice you can give would be greatly appreciated as I'm already pulling my hair out!

Thanks

Dave

imriskal
Posts: 399
Joined: Wed Aug 15, 2012 8:18 am

Re: Newbie 'Replace' Question

Postby imriskal » Thu Aug 13, 2015 8:40 am

Hi Dave,

Could you please share your graph and a sample of input file throwing the error? I would like to see the error you get for myself.

A general advice I can give you right away is that you should be careful about the second argument of replace function. It is not a string as it might seem, it is a regular expression. So for example special characters should be escaped. See the documentation for replace function http://doc.cloveretl.com/documentation/ ... l2-replace

Thanks.
---
Lubos Imriska
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com

daveinhants
Posts: 4
Joined: Wed Aug 12, 2015 11:14 pm

Re: Newbie 'Replace' Question

Postby daveinhants » Thu Aug 13, 2015 9:10 am

Hi Lubos,

Thanks for your help.

Attached you can see the graph and the transformation I have tried to apply that failed.

Then I have shown the graph processing successfully without that Reformat box and an excerpt of the data that shows the field I'm trying to apply the transformation on.

The strange thing is I used the same syntax to apply a similar transformation on another field (replacing - with / in a string) and it worked!

Dave
Attachments
clover1.JPG
failing example
clover1.JPG (73 KiB) Viewed 3389 times
clover.JPG
working graph with data input excerpt
clover.JPG (138.86 KiB) Viewed 3389 times

daveinhants
Posts: 4
Joined: Wed Aug 12, 2015 11:14 pm

Re: Newbie 'Replace' Question

Postby daveinhants » Thu Aug 13, 2015 9:20 am

Ultimately I will want to replace several different values with new ones (Y, N, NA, blank etc). Would I need to have some kind of if, then, else statement to achieve this?

Sorry if this is too basic I'm a glorified user not a developer! :-)

Thanks, Dave

slechtaj
Posts: 192
Joined: Wed Aug 15, 2012 8:18 am

Re: Newbie 'Replace' Question

Postby slechtaj » Mon Aug 17, 2015 5:32 pm

Hi Dave,

I think that Lubos wanted to take a look at the GRF file (or even better the whole project including the source CSV file). To me, it doesn't seem there is actually a problem with the replace function. The thing is the issue might have been caused by several other reasons. In order to find this out I would need to see the long and/or the GRF file.

Regarding the if - else (or switch - case) statements, it really depends on the particular case. Sometimes even one smart regular expression can handle multiple (or all) different cases.
Jan Slechta
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com

How to speed up communication with CloverCARE support


cron