cancel
Showing results for 
Search instead for 
Did you mean: 

Solution required for one ETL scenario in BODS

former_member208402
Active Contributor
0 Kudos

Hi

Can anyone help me in providing solution for the below scenario.

We have source data like this.

CountryCity
IndiaHyderabad          
India          Bangalore
IndiaMumbai
USASanjose
USANew york
USABoston
USA Los angeles

Now, we want output like below.

CountryCity
IndiaHyderabad,Bangalore,Mumbai
USASanose,New york,Boston,Los angeles

Can any one help us for this scenario with detailed steps/logic we need to implemented to achieve the above output.

Thanks,

Ravi kiran

Accepted Solutions (1)

Accepted Solutions (1)

former_member187605
Active Contributor
0 Kudos

If you know the maximum number of cities in advance, use a Reverse_Pivot transform. Then concatenate all pivot columns into 1.

former_member241220
Participant
0 Kudos

Hi Ravi Kiran,

If you found the solution regarding this requirement. please can you post here.It will help to me and another team members.

Thanks and Regards,

Murali

former_member208402
Active Contributor
0 Kudos

Hi Murali,

This was the question asked in an interview.

I didn't work on this scenario and the solution suggested by Dirk would work for this scenario.

Thanks,

Ravi kiran.

former_member241220
Participant
0 Kudos

Hi Ravi Kiran,

Even I didn't work on this scenario, but I have one requirement seems to be same like this. If you want I will share.

Thanks and Regards,

Murali.

Answers (1)

Answers (1)

Former Member
0 Kudos

Unfortunately, Reverse pivot will only work if you know the number of columns ahead of time like Dirk Venken mentioned. However, if the number is unknown and you would like to still do something like this, you can use a SQL transform with a query that groups by country and concatenates the list of city strings into a comma delimited list.

For MySQL I think there is a group concat function built in, but for SQL Server you may need something like this: How to use GROUP BY to concatenate strings in SQL Server? - Stack Overflow.

This will allow you to get a comma delimited list (just add the city as another piece of the select) and map it into your dataflow like you normally would!

We use something like this in one of our batch jobs and when joined to a driver table to cut down on rows (say 4000-10000 rows per batch) it runs quite fast - less then half a second. for a 4m row database table it runs in about 20 seconds.