Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: If input field is numeric then cast it to number else leave it alone

  1. #1

    Default If input field is numeric then cast it to number else leave it alone

    Hi in my transformation, one of the incoming fields from input file comes as "01", "023", "ABC" etc that I need to do a database lookup against. The values in database that I am looking up against are stored as 1, 23, "ABC" etc. Any ideas for good ways/step to accomplish this? Basically I want to cast/convert the incoming value to numeric if they are numeric (in order to remove the leading zeros) and leave them alone if they are not numeric. Any features besides javascript to do this? The numeric values will always be whole integers (01, 023 etc) - no decimals. Thanks.

  2. #2
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    Eventually it comes down to trimming leading zeroes from a string.

    I would use a User Defined Java Expression of the form fieldname.replaceFirst("^0+(?!$)", "")
    So long, and thanks for all the fish.

  3. #3

    Default

    That works! Thank you sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.