cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Transformation for data

walkerline117
Contributor

Hiโ€ฆ

We have below requirment:

Original data from data soure(e.g. database)
image

Hereโ€™s what we need to transform to:
image

Appreciate any kind of suggestions.

Thanks
Han

5 REPLIES 5

del
Contributor III

Thereโ€™s got to be an easier way, but I succeeded with a Mapper containing the following expression and then a Splitter following the Mapper.

$Errors.replace(/\d+. /g,โ€œ|โ€).split(โ€œ|โ€).map(x => {โ€œNameโ€:$Name,โ€œFMNOโ€:$FMNO,โ€œPhone #1โ€:$[โ€˜Phone #1โ€™],โ€œPhone #2โ€:$[โ€˜Phone #2โ€™],โ€œEmailโ€:$Email,โ€œErrorโ€:x}).filter((v,k)=>v.Error!=โ€œโ€)

del
Contributor III

LOL, I challenged myself to make it better. Itโ€™s not prettier, but youโ€™re not stuck to hard-coding column names.

$Errors.replace(/ *\d+. /g,โ€œ|โ€).split(โ€œ|โ€).map(x => $.mapValues((v1,k1)=>k1 == โ€œErrorsโ€ ? x : v1).mapKeys((v2,k2)=>k2 == โ€œErrorsโ€ ? โ€œErrorโ€ : k2)).splice(1)

Surely, someone can improve on this evenโ€ฆ

Thanks so much, it really helps.

The only thing is that the result comes into different groups by ppl name.
How to flat the result so everything goes into one structure(no group)

Thanks

Adding a splitter snap after the mapper flattened the data for me.

Also, thereโ€™s a dozen ways to do this I think. The expression I provided keeps the pipeline short, but itโ€™s hard to interpret if you need to debug. You can simplify the expression and use additional snaps. Attached is a pipeline with just two possible options that achieve the same results.

community-1794_2017_12_14.slp (10.7 KB)