cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for Checking 2 values and building context

former_member581827
Participant
0 Kudos

Hi,

I need to check whether the value in first argument is same as in 2nd Argument, if so then pass that value else add context change.

I am using below UDF for the same

int i=0,j=0;

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

  for(j=0;j<b.length;j++)

    if(a[i].equals(b[j]))

    result.addValue("He");

      else

    result.addContextChange();

  }

A          B

123     234

456     456

789

234

678

Output should be

[]

456

[]

234

[]


Appreciate your help.

Thanks,

CH..

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi CH

Try out the logic below. Your UDF should be of type "Queue".


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

  boolean found = false;

  for (int j = 0; j < b.length; j++) {

    if (a[i].equals(b[j])) {

      result.addValue(a[i]);

      found = true;

      break;

    }

  }

  if(!found) {

    result.addContextChange();

  }

}

Rgds

Eng Swee

former_member581827
Participant
0 Kudos

Hi Swee,

Thanks for your reply and it did worked.

Now if i am having like this

A        B

X       ABC

X        DEF

X

123

X

456

X

X

The output should be

[]

[]

[]

ABC

[]

DEF

[]

[] -- Context change.

Thanks,

Ch


engswee
Active Contributor
0 Kudos

Hi CH

Good to know it worked for your first scenario.

For your second scenario, can you clarify what is the relationship to match 123 with ABC, and 456 with DEF? Also, what are the values of X from input A?

It would be much easier if you provide values from an actual payload instead of hypothetical values.

Rgds

Eng Swee

former_member581827
Participant
0 Kudos

Hi Swee,

Basically in my First queue i am having 5 entries  with key123 as one of the field and in second queue i might have 5 entries with Key123 or some times it might not be 5 it might be existing or not also.

I need to pass 2nd queue entry to only for the first queue entry where this key matches if not i need to pass Empty context.

Remember second queue might exist or not also and both queue 1, queue2 are in same level.

Hope this  clarifies.

i was  thinking based on my example provide if Queue1 has value X then pass [] else pass the first value of Queue 2 to the first non exisiting value X.

Correspondingly 2nd non X value should be replaced with 2nd value of QUEQE2.

Thanks,

Ch

engswee
Active Contributor
0 Kudos

Hi CH

Sorry, I don't really follow your logic. As I mentioned before, real life example of source payload and expected output would be useful.

Rgds

Eng Swee

Answers (0)