Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Convert Data Stage Expression to User Defined Java Expression

  1. #1
    Join Date
    Apr 2014
    Posts
    4

    Default Convert Data Stage Expression to User Defined Java Expression

    Can some help me in converting this datastage expression to UDJE or a different step to make it work in pentaho.

    If Trim(lnk_tfmDate.SOLD_TO_COUNTRY) = '' Then Trim(Convert('"','',lnk_tfmDate.SOLD_TO_COUNTRY)) else lnk_tfmDate.SOLD_TO_COUNTRY

    Thanks

  2. #2
    Join Date
    Apr 2008
    Posts
    4,696

    Default

    When coming to Pentaho, you have to take a step back from "This is what I do in my existing system" to "These are the steps that I need to accomplish"

    So:
    1) You need to determine what the trim of lnk_tfmDate.SOLD_TO_COUNTRY is
    --> There's a String Operations step that will allow you to calculate the trimmed value of this field.
    --> You could use trim(lnk_tfmDate.SOLD_TO_COUNTRY) in your table input (assuming Table Input)
    --> You can set the trim to both for most other inputs
    2) You want to assign one of two values based on the value of step 1.
    --> You can use the Formula step ( if([step1]="";truevalue;falsevalue) )
    --> You can split the stream using Filter Values and reconnect it
    --> You can use a UDJE similar to step1.equals('') ? truevalue : falsevalue This may cause null pointer exceptions... I'm not sure.

    Most of the time, built-in steps will be faster than scripting, but UDJE is one of the exceptions to that rule.
    There are MANY ways to write the same thing in PDI... Explore a few of them, load them with a LOT of data, and see which is fastest.
    Last edited by gutlez; 04-25-2014 at 06:08 PM.

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

    Default

    One more try: There's no null handling in the BASIC transformer stage, so we talk DataStage 8.5 or newer.
    If that subrecord field is null, the condition will evaluate to FALSE and the expression does nothing at all.
    Otherwise, if the field value is an empty string or just whitespace characters, the nested functions first remove all double quotes and thereafter all leading and trailing whitespace.
    Not much sense in it, eh?

    I guess a useful translation of that BASIC expression to single line Java will look very much like shown here:

    Name:  UDJE.jpg
Views: 56
Size:  12.5 KB

    Code:
    // just for c&p convenience:
    
    SOLD_TO_COUNTRY == null ? null : SOLD_TO_COUNTRY.replaceAll("\"", "").trim()
    So long, and thanks for all the fish.

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.