$ 0 0 you need to change your udf like below if(str1.length() > 10) then use str1.substring(0,9) else str1.