cancel
Showing results for 
Search instead for 
Did you mean: 

UDF query

former_member183906
Active Contributor
0 Kudos

hi


We have a field TEST - when it comes as a three character string of the same value (AAA, BBB, bbb,ccc etc.) -small or CAPS same value - we need to pass NULL for it.Otherwise watever value comes it shud pass.

can u please share UDF to be written for it.

rgds

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

No need for UDF, you can use this mapping:

Hope this helps,

Mark

former_member183906
Active Contributor
0 Kudos

hi

the req is we have to check if the TEST value is of 3 character and if all 3 characters in the TEST are identical or not ?

rgds

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

The mapping provided will only pass all characters that have a length > 3, if you will be checking for duplicates add this mapping after remove context: sort:lexicographical ascending -> splitByValue:ValueChanged -> collapseContext ... That logic will ensure that only unique values are passed.

Regards,

Mark

Former Member
0 Kudos

Hi

Please create the UDF as below

Take str as input string.

if( str.length() == 3)
{
char fst = str.toLowerCase().charAt(0);
char snd = str.toLowerCase().charAt(1);
char thd = str.toLowerCase().charAt(2);

if( fst == snd &&  fst == thd)
{
return null;
}
else
{
return  str;
}
}
else{
return str;
}

output:

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I agree with Iñaki, the best solution is using pattern. Take the first character of TEST and check if the pattern matchs.

So:



String inputText= "bbb";





Pattern p = Pattern.compile(inputText.substring(0,1)+"{3}"); //The patter is first letter{3}





Matcher m1 = p.matcher(inputText);



If m1.matches()


return null;
Former Member
0 Kudos

Hi,

Create a udf with string input var1 and the following code:

String strVal = var1.toLowerCase();

if(strVal.length() != 3) return var1;

for(int i = 0; i < strVal.length() - 1; i++){

          if(strVal.charAt(i) != strVal.charAt(i+1)) return var1;

}

return null;

Regards,

Koen

iaki_vila
Active Contributor
0 Kudos

Hi,

If i understand right you need to search a pattern inside the string. I recommend you to use regular expresions for your  UDF, check this link http://www.tutorialspoint.com/java/java_regular_expressions.htm

Regards.