cancel
Showing results for 
Search instead for 
Did you mean: 

Need help on UDF.

Former Member
0 Kudos

Hi All,

I have a requirment like

my source have 2 fields

field1 having data 1cc2cc3cc4cc5cc

feild2 having data accbccdddcceccfffffcc

in need output like 1cc2cc333cc4cc55555cc please help me to get this type of output.

Note cc means context change, we need to reah values of contexts with source and generate like that.

Thanks,

Venu.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

Why do u need a UDF? Simply use "UseOneAsMany" function to generate ur output.

Filed1----

Filed2---- UseOneAsMany - Output

Field2----

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

thanks for quick reply, i have tried "UseOneAsMany" function but its not working.

one thing i forgot to mention, values in both queues are not same, i gave same vaules in example but in my case first queue having less values than second queue.

thanks,

Venu.

Former Member
0 Kudos

I don't see any reason why it should not work, paste ur mapping screenshot with dispaly queue output on "UseOneAsMany" function.

Former Member
0 Kudos

Hi Amit here is screen shot.

Former Member
0 Kudos

You have to revist ur mapping because from the display queue output it's quite clear that the no of context is not the same...

Former Member
0 Kudos

Thanks Amit,

thats what i mentioned in second post, queues are not having same length, so even if they are not same length do we achive this using any UDF.

thanks,

Venu

Former Member
0 Kudos

Hello,

I think you mentioned this statement once i posted my reply so that's the reason i overlooked it.

one thing i forgot to mention, values in both queues are not same, i gave same vaules in example but in my case first queue having less values than second queue.

Anyway, u can write a UDF but since the number of context are not same so u have to identify a logic where u can determine for which context (field2) which field1 value needs to be replicated. BTW, <null> can come in between ur actual values as well? If not then i think ur logic can be build around that, where for all "true" values u can read field 1 values one by one.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi All,

Any one can help me on UDF code please.

Thanks,

Venu

azharshaikh
Active Contributor
0 Kudos

Hi Venu,

Can you share the Input and required Output payload XML

Also share the possible combinations/variations that can appear in Input file.

Regards,
Azhar

Former Member
0 Kudos

Hi Azhar,

Its very complext and huge XMLs, now i need the UDF logic for two fields mapping given below.

my source have 2 fields

field1 having data 1cc2cc3cc4cc5cc

feild2 having data accbccdddcceccfffffcc

in need output like 1cc2cc333cc4cc55555cc please help me to get this type of output.

Note cc means context change, we need to reah values of contexts with source and generate like that.

values in both queues are not same, i gave same vaules in example but in my case first queue having less values than second queue.


Hope this is can help you.


thanks,

Venu.

azharshaikh
Active Contributor
0 Kudos

Hi Venu,

For the Input given in your previous post, the output can be achieved using the UDF as follows:

public String calculate1(String var1, String var2, Container container) throws StreamTransformationException{

String temp = "";

if(var2.length() > 0)

for(int i=0; i<var2.length();i++)

temp = temp+var1;

var1 = temp;

return var1;

}

Check if it helps. We can build on this UDF as per your requirement.

Regards,
Azhar

Message was edited by: Azhar Shaikh

Former Member
0 Kudos

Hi Azhar,

Thanks for the prompt reply, but its not meeting my isssue. .

my structure is

Field1  Field 2 

1          a

cc        cc

2         b

           b

cc       cc

3         d

           d

           d

cc       cc

4         e

and my output needs to be.

target Field output.

   

1

cc

2

2

cc

3

3

3

cc

4

hope you got this.

Thanks for prompt help.

THanks,

Venu

former_member184720
Active Contributor
0 Kudos

So in your first queue there is always a context change after each value?

If so why doesn't useoneasmany work?

However below UDF shoudl return the output that you requested for above sample content.

Execution type : All values of context

for( int i=0;i<var2.length;i++)

{

result.addValue(var1[0]);

}

var1 -> your first queue

var2 -> second queue

Former Member
0 Kudos

Sorry its not working , weare getting ArrayoutofIndex error.

former_member184720
Active Contributor
0 Kudos

For your input it should work.

Share your display queue screenshot.

Former Member
0 Kudos

is it var1[i[ in this statement ..result.addValue(var1[0]);

former_member184720
Active Contributor
0 Kudos

for your input and output, it should be


result.addValue(var1[0]);