cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to check the values in the context

Former Member
0 Kudos

Hi All,

Can anyone please help me to check the values in the context.

I have four context changes coming from the source and have to check the values in the context. If any value from in the context is Y then the output has Y else X.

INPUT:

X

contextchange

X

X

contextchange

X

X

Y

contextchange

X

Y

Y

X

contextchange

Output:

X

contextchange

X

contextchange

Y

contextchange

Y

contextchange.

Cheers,

Smith.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

This can be done without using UDF, this is assuming that you only have two inputs (X and Y)

You can use the mapping below:

input --> sort: lexicographical (case insensitive) descending --> collapseContexts --> splitByValue --> target node

explanation: the sort function, sorts each letter per context in lexicographical order. The output is that if there is a Y, it will always be placed in the first position of the context. Then you collapse the context so that the duplicates/excess entries are removed (only the first value is retained). Then the splitByValue does the splitting.

Hope this helps,

Former Member
0 Kudos

Thanks Mark & Rohit,

Both the solutions were spoton. But full points to the easiest solution

Cheers,

Smith.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try the following UDF,

Use UDF Execution Type = Context.

int cnt = 0;
for(int i = 0;i<inputValue.length;i++)
{
  if(inputValue<i>.equals("Y"))
  {
    cnt++;
  }
}
if(cnt > 0)
{
  result.addValue("Y");
}
else
{
  result.addValue("X");
}

-Rohit.