cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate the target node based on the number of values in a field

Former Member
0 Kudos

Hi Experts,

I have a requirement, where I have to genrate the target node according to the number of values in a field in the source structure.

Eg:

Source:

</source>

<name>Reyaz</name>

<empno>2215</empno>

<mobno>9885313131,9836123123</mobno>

</source>

I want the out put as

<target>

<tagetnode>

<name>Reyaz</name>

<empno>2215</empno>

<mobno>9885313131</mobno>

</tagetnode>

<tagetnode>

<name>Reyaz</name>

<empno>2215</empno>

<mobno>9836123123</mobno>

</tagetnode>

</target>

Can some body tell , How I can achieve this.

Thanks&Regards,

Reyaz

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Reyaz,

Create a queue udf Addnode with one input argrument input and add this code:

Imports: java.*;

//write your code here

String werks = input[0];

StringTokenizer st = new StringTokenizer(werks,",");

while(st.hasMoreTokens())

{

result.addValue(st.nextToken());

}

Now map like this.

mobno --> Addnode(udf) --> targetnode

name --> copyvalue --> name

empno --> copyvalue -->empno

mobno --> Addnode (udf) --> splitbyvalue --> mobno.

I just tested with your test case. Its working and it is giving the output as you expected. Here test thorougly, I doubt on copy value, if you run into any issues then instead of copyvalue you may need to use useoneasmany function.

Regards,

---Satish

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Reyaz,

Your logic can be written by a udf where you need to break your targetnode based upon your mobno. Then for the rest of the fields name and empno, you can use oneusasmany or copyvalue and for mob no udf with split by value should work. Let me write a udf and give it to you.

Regards,

---Satish

Former Member
0 Kudos

Hi,

Try with UseOneAsMany function or create an UDF to solve this.

Regards,

Sarvesh

former_member200962
Active Contributor
0 Kudos

If we strictly go by the source structure provided, useOneAsMany cannot be used!

Regards,

Abhishek.

Former Member
0 Kudos

Hi,

thanks for your replies. Not exactly two. It can be upto 30 at max. I dont think that we can use useOneAsMany function. Because, this not dependent on the occurence of a field. It is dependent on the number of values in a single field.

Thanks,

Reyaz

Former Member
0 Kudos

Then use udf.

Go through this udf and see the ans by Sunil.

former_member200962
Active Contributor
0 Kudos

Are you going to get only two values (mobile numbers)?