cancel
Showing results for 
Search instead for 
Did you mean: 

Reg:UDF help

Former Member
0 Kudos

Hi ...

Can you please helpin writing the udf for the below requirement...

In first queue.. i am getting the below values..like

A

B

C

A

D

B

In the second queue, the values are...

10

20

30

40

70

60

In the output i need to get values like

50 (here A is repeating .so we need to sum the values od A [10+40])

80 (here B is repeating .so we need to sum the values of B [20+60])

30

50 (here A is repeating .so we need to sum the values od A [10+40])

70

80(here B is repeating .so we need to sum the values of B [20+60])

Input1 Input2 Output

A 10 50

B 20 80

C 30 30

A 40 50

D 70 70

B 80 80

Can you please help in witing this UDF...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try to using this UDF. I was tested, working fine.


int sum = 0;
 for(int i=0;i<a.length;i++)
     {
        for(int j=0;j<a.length;j++)
           {
	if(a<i>.equals(a[j]))
	{
	    sum = sum + Integer.parseInt(b[j]);
	}
           }
      result.addValue(sum+"");
      sum = 0;
     }

Before Calling UDF, please check in mapping

First Queue value having Type node.

Second Queue value having Value node.

So In mapping,

Type ---> CollapseContext ---> A

Value ---> CollapseContext ---> A

A ---> Call UDF ---> SplitByValue(Each alue) ---> Output Node

I Hope solve ur issue.

Thanks & Regards

Vijaykumar

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Vijay/Mark..

Thanks for your help.. I have tried the UDFs which you have given.It is working fine...

Regards,

Leela

former_member187339
Active Contributor
0 Kudos

Hi Leela,

No need for UDF, tyr doing like this


input1-->removecontext-->sortbykey(descending)-->splitbyValue(valuechange)-->formatbyexample-->AddUDF->output
			    input1-->removecontext-->sortbykey(descending)
			    input2-->removecontext-->

PS: AddUDF : I think you will eb able to write this

Regards

Suraj

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

You can try this mapping:

Legend:

LCSI = Lexicographical Case Insensitive Ascending

VC = Value Changed

input1 --> removeContext --> UDF (input1)

input1 --> removeContext > sortByKey: LCSI> formatByExample --> sum --> removeContext --> UDF (input2)

input2 --> removeContext --> / ____________________________/

input1 --> removeContext --> sort: LCSI --> splitByValue:VC --> /

input1 --> removeContext --> sort: LCSI --> splitByValue:VC --> collapseContext --> UDF (input3)

The UDF is of ContextType

arguments: input1, input2, input3

import java.util.Hashtable;

Hashtable inputLookUpTable = new Hashtable();

for(int a=0;a<input2.length;a++){

inputLookUpTable.put(input3[a],input2[a]);

}

for(int a=0;a<input1.length;a++){

result.addValue(inputLookUpTable.get(input1[a]));

}

I've already tried this and it is working...you might need to add splitByValue (each value) after the UDF

hope this helps,