Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Modified Java Script Value > execution of a function only one time, not once per row

  1. #1

    Default Modified Java Script Value > execution of a function only one time, not once per row

    Hi all,

    I'm wondering if it's possible to execute a javascript function (snippet of code into a Modified Java Script Value) one time, before processing first row and not once per each row. In fact in the Mod Java Script Value Step I initialize a cryptographic key and a mac (Message authentication code) provider, but I'd like to reuse this provider instance and not to instantiate per each row.
    There is a chance to achieve this goal?

    Or maybe there are other strategies, maybe I could use a type of step to load into a buffer same data... Or I could write a Java class with "Singleton pattern"... Any hint would be appreciated.

    Thank you.
    Gianpiero
    Last edited by gianpieropiccolo; 04-04-2016 at 10:18 AM.

  2. #2
    Join Date
    Aug 2011
    Posts
    360

    Default

    Hi,

    Just add a new script (new tab), right click on the tab and choose "Start script".
    Then it will be executed once at transformation initialisation. Js variables created there
    are then accessible in your main script.
    That a good place to put custom function (even if they are ised on each rows!) and constant variables.

    If you need also to close ressources at the end of transformation, create another script tab, right click, and choose
    "End script". It will be called once after the step has processed every rows.

  3. #3

    Default

    Thank you very much!
    Thanks to your suggestion, I googled for "Startup script" in Pentaho and found other optimization hints here: https://help.pentaho.com/Documentati...P0/100/040/010 (it includes your suggestion).

    Regards.
    Gianpiero

  4. #4
    Join Date
    Aug 2011
    Posts
    360

    Default

    Yep,

    And the best advice is dont use javascript unless your are forced to!
    It is really slowlier than other steps. Some times some java user expression can do the trick.
    For big business complicated logic, the best is:
    - write a java library that do the hard work. Create some classes (beans) with getters and setters that are pentaho-type-friendly
    (Long, Double, Boolean, String, Date, Byte)
    - use the user defined java class to wire the input/output rows of pentaho woth your library.

    You'll get something reaaallyyy efficient!

  5. #5

    Default

    Thank you for your advice. I thought that the javascript were compiled in java bytecode, some sort of pre-compilation in java source and then java compilation in bytecode. This idea came to me when I got an error about bytecode exceeding 64K limit. Maybe the javascript is embedded into a java class? What is the optimization level, indeed? what version of ECMA script is used?
    Thanks.
    Gianpiero
    Last edited by gianpieropiccolo; 04-06-2016 at 06:50 AM.

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.