Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: How does this User Defined Java Expression work ?

  1. #1
    Join Date
    Dec 2011
    Posts
    18

    Default How does this User Defined Java Expression work ?

    Hi Everybody!

    I am trying out this UDJE step to generate the system time in PST.

    I create a transformation with just that step. here is the ktr
    sysdate_1.ktr

    It says Sorry, during preview there werent any rows to display for this step.

    I created another one with generate rows , but that gives an error like
    sysdate.ktr2/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : Unexpected error
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : org.pentaho.di.core.exception.KettleException:
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : org.pentaho.di.core.exception.KettleValueException:
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : org.codehaus.janino.CompileException: Line 1, Column 5: Cannot determine simple type name "Date"
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : Line 1, Column 5: Cannot determine simple type name "Date"
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) :
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) :
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : org.codehaus.janino.CompileException: Line 1, Column 5: Cannot determine simple type name "Date"
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) : Line 1, Column 5: Cannot determine simple type name "Date"
    2012/03/23 09:13:19 - User Defined Java Expression.0 - ERROR (version 4.2.0-GA, build 15694 from 2011-08-24 11.46.44 by buildguy) :


    Whats going one. Can somebody help me with this ? Appreciate the help. I got the idea of using UDJE to generaet rows from these reads:
    Drop a
    User Defined Java Expression from the Scripting category. Add a new field
    named
    shortInteger and type the following text in the Java expression column:
    (int)Math.floor(Math.random()*3650)
    . Also, select Integer in the Valuetype column.2. Do a preview and check the new shorInteger field; it will have values between 0
    and 3649.

  2. #2
    Join Date
    Nov 2008
    Posts
    777

    Default

    The UJDE is basically a one-liner, i.e., the right side of a java assignment expression. What you are trying to do is chain java statements together. Javascript would be more suitable - for your example at least. Like so:

    Code:
    currentTime = new java.util.Date();
    sdf = new java.text.SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
    sdf.setTimeZone(java.util.TimeZone.getTimeZone("America/Los_Angeles"));
    var c_in_pst = sdf.format(currentTime);
    Note, however, that most transformation steps are row processors so steps like the UJDE and Javascript need rows to do their work. A Row Generator step, for instance, in front of the above code in a Javascript step will produce your desired output.
    Attached Files Attached Files
    Last edited by darrell.nelson; 03-23-2012 at 02:57 PM.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  3. #3
    Join Date
    Nov 2008
    Posts
    777

    Default

    I could be wrong but I don't think creating a new java object will really work in a UJDE. However, I frequently use static methods and build off them as much as they allow. For instance:

    Code:
    java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.FULL,java.text.DateFormat.FULL).format(currentTime)
    Attached Files Attached Files
    Last edited by darrell.nelson; 03-23-2012 at 03:54 PM.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    You can create new objects. For example if you concatenate a lot of text you can use a StringBuilder class to do this.

  5. #5
    Join Date
    Nov 2008
    Posts
    777

    Default

    I stand corrected. My example rewritten like this does indeed work:

    Code:
    java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.FULL,java.text.DateFormat.FULL).format(new java.util.Date())
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

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.