cancel
Showing results for 
Search instead for 
Did you mean: 

UDF

0 Kudos

Hi

I need a UDF to generate the Sequence Number. Counter and Index won't work in my example. I need to generate sequence number incrementing only when there is a Context Change. I cannot use collapse context as I need to keep all the values.

It is like Index function. If INDEX works like this -


when ever there is a context change, we can reset the counter.

In my scenario, UDF should work as

when ever there is a context change, Increment the counter, other wise keep the same.

eg. input to INDEX/UDF

A

context change

B

B

context change

C

context change

D

D

context change

INDEX Function Output is

1

context change

2

3

context change

4

context change

5

6

context change

Desired UDF output should be

Index Output is

1

context change

2

2

context change

3

context change

4

4

context change

Edited by: bprashanth19 on Aug 5, 2010 10:50 PM

Edited by: bprashanth19 on Aug 5, 2010 10:50 PM

Accepted Solutions (1)

Accepted Solutions (1)

jyothi_anagani
Active Contributor
0 Kudos

Hi Prasanth,

Map Like This..


Input ---> collapseContext ----> index(1,1) ----> splitByValue(Each Value) ---\
                                                                         input ----->useOneAsMany ---->output
                                                                        input /

I have tested this mapping passing the same input which you have mentioned.

got the output like


1
context change
2
2
context change
3
context change
4
4
context change

Regards

Jyothi A

Answers (4)

Answers (4)

0 Kudos

Thank you Jyothi.That was eaxctly the solution I was looking for.

Thanks Das for the UDF, I had some challenges implementing the UDF. Though I created the variable count in target node, UDF was still given error as count not defined.

Former Member
0 Kudos

Hi,

u can obtain this using a simple UDF



decalre a global variable.

int count = 1;


keep execution type = context
copy paste the below code

for(int i= 0;i<var1.length;i++)
{
result.addValue(count+"");
}
count = count+ 1;

Former Member
0 Kudos

Please use index function with property entire document inplace of context.

See if it works.

Thanks,

Hetal

Former Member
0 Kudos

Index function can be used.

Check the index property, it can reset after context change.

Regards

Liang