How to create single value record from multivalue CSV

I have a CSV file with the following style of output:

name, pet
-----------
simon, dog
simon, cat
dave, hamster
dave, pig
mike, mouse

I have used a REFORMAT to create a list of just names, then DEDUP
to create a list of distinct names. I then attempted to compare the master
and slave feeds from this to create the following…

name, pet
------------
simon, “dog,cat”
dave, “hamster,pig”
mike, “mouse”

…but so far I can’t do it.

Has anyone seen a solution to this before?? Is there any built in transforms that I can use to do this or attempt to create a customer jar?

I’m really stuck. Any ideas welcome!!

TIA.

Hi, it’s really easy :wink: : read the data, sort them by name and then use the Denormalizer component.

Doesn’t that mean my TL transform has to contain a hardcoded listing of each user_name?

It hasn’t. You need only write TL function addInputRecord() where you remember a new pet (eg. add it to list) and getOutputRecord() function, which fills output field with all stored pets; in clean() function you can clear the list.

Sorry! I’m really confused. This is what I’ve tried and it only picks up the last pet the individual has for all names.

How can I concatenate the pets together or, at least get another field with the second and third pets?

//#TL
string name;
string pet;
string all_pets;

function addInputRecord() {
name = $name;
pet = $pet;
}

function getOutputRecord() {
$name :=name;
$all_pets := pet;

}

 <attr>//#TL
string name;
string pet;
string all_pets;

function addInputRecord() {
name = name;
pet = pet + ',' + $pet;
}

function getOutputRecord() {
$name :=name;
$all_pets := pet;
pet="";
}


</attr> 

Hi there

I’ve tried the above, but I end up getting a none unique list of pets per each user. So for the last user in the sorted file, their list of pets will contain all pets from all the above users, not just the pets that belong to them.

How can I clear down the list before getObjectRecord processes each name?

ignore that!

I’ve sorted it.

Thanks