cancel
Showing results for 
Search instead for 
Did you mean: 

Context problem

Former Member
0 Kudos

hi all,

i have a problem regarding contexts.

for example i have an input:

A

B

C

context change

D

E

context change

F

context change

G

H

I

if i do collapsecontext, the output would be

A

D

F

G

but in my case, the output should be the last value of per context:

C

E

F

I

is this possible without using UDF?

Thanks all!

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use sort:lexicographical case insensitive descending before your collapseContext.

Hope this helps,

Mark

Former Member
0 Kudos

Hi Mark,

what do you mean sort lexographically? I don't need to sort them in alphabetical order. The letters are just examples. It can be numbers.

Former Member
0 Kudos

B

C

A

context change

D

F

context change

E

context change

H

I

G

if i sort this in a descending order, output would be

C

D

E

I

but i need to get the last value which is

A

F

E

G

thanks though for the suggestion.

is this possible w/out UDF?

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Since the inputs are not ordered and you need the last value per context, this is only possible via UDF.

Regards,

Mark

Former Member
0 Kudos

try this with a udf.

mapping:

source>reverse>collapse context-->target

UDF:

execution type:All Values of context


public void reverse(String[] var1, ResultList result, Container container) throws StreamTransformationException
{
int l=var1.length;
int i=0;
while(i<l)
{
	result.addValue(var1[l-i-1]);
	i++;
}
}

Thanks,

Anand

Former Member
0 Kudos

Hi Anand, it worked perfectly. Thanks!

Answers (1)

Answers (1)

former_member463616
Contributor
0 Kudos

Hi,

Try in message mapping.

Source --> sort (descending) --> CollapseContext ---> Target

Regards,

P.Rajesh

Edited by: Rajesh_1113 on May 26, 2011 1:25 PM