Forum Discussion

walkerline117's avatar
walkerline117
Contributor
8 years ago

Transformation for data

Hi…

We have below requirment:

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

Here’s what we need to transform to:

Appreciate any kind of suggestions.

Thanks
Han

5 Replies

  • del's avatar
    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's avatar
      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…

      • walkerline117's avatar
        walkerline117
        Contributor

        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

  • Do something like the below steps.

    1. In the Mapper - Errors.split(‘.’) - but it will not split when you have only one error. You need to come up with some logic there.
    2. add a JSON splitter and
    • split in on Errors
    • use scalar parents checkbox or add the path you want to. The former should work for this.