Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: udjc issues with variable scope during transformation or job invokation

  1. #1

    Default udjc issues with variable scope during transformation or job invokation

    Hi,

    I am creating a reusable transformation that will implement checkpoint for a transformation or job by creation of touch files.
    This reusable transformation would be called by any job.
    The plan is use UDJC(user defined java class) to invoke a job or transformation based on the argument that is given to this reusuable component.
    The problem!!!
    1) i am new to udjc
    and ...
    The transformation or job invoked by UDJC is unable to access the value of the variables(the scope is at "root" level) which are set by the master/parent job.I am able to run in spoon (4.4) but it fails in Linux (pentaho version is 4.3)
    But if I change the scope to JVM level it works in Linux os.

    How do I pass all the variables to the "invoked" transformation/job without using setvariables in udjc. i dont want to use setvariables(we have to explicitly mention the variables) because i don't know how many variables will the invoked trans/job needs .do we have any method in udjc? like variablespace etc...
    please provide code snippets as well if possible...

    this is the code for the udjc
    ----------------------------------------------------------------------------------------------------------------
    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
    {
    Object[] r=getRow();
    if (r==null)
    {
    setOutputDone();
    return false;
    }


    KettleEnvironment.init();
    EnvUtil.environmentInit();
    r = createOutputRow(r, data.outputRowMeta.size());

    String input_param = get(Fields.In, "input_param").getString(r);


    TransMeta transMeta = new TransMeta(input_param);


    Trans trans = new Trans(transMeta, getTrans());


    trans.execute(null);
    trans.waitUntilFinished();
    Result result = trans.getResult();
    get(Fields.Out, "result").setValue(r, Boolean.valueOf(result.getResult()));
    get(Fields.Out, "errors").setValue(r, Long.valueOf(result.getNrErrors()));
    get(Fields.Out, "err_desc").setValue(r, String.valueOf(result.getLogText()));


    // Send the row on to the next step.
    putRow(data.outputRowMeta, r);


    return true;
    }
    -------------------------------------------------------------------------------------------------------------------------------

    regards,
    pramod.

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

    Default

    Maybe you should add one line of code:

    Code:
    trans.shareVariablesWith(sdi);
    So long, and thanks for all the fish.

  3. #3

    Default

    Quote Originally Posted by marabu View Post
    Maybe you should add one line of code:

    Code:
    trans.shareVariablesWith(sdi);
    I am getting following error.
    org.codehaus.janino.CompileException: Line 40, Column 26: No applicable constructor/method found for actual parameters "org.pentaho.di.trans.step.StepDataInterface"; candidates are: "void org.pentaho.di.trans.Trans.shareVariablesWith(org.pentaho.di.core.variables.VariableSpace)", "void org.pentaho.di.core.variables.VariableSpace.shareVariablesWith(org.pentaho.di.core.variables.VariableSpace)"

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

    Default

    Nevertheless, sharVariablesWith() is the method you should be interested in.
    So I did what you should have done: I looked at the available Kettle source code.

    Code:
    trans.shareVariablesWith(this);
    Another trace to follow is method setMappingParameters() - search Mapping.java for that.
    So long, and thanks for all the fish.

Tags for this Thread

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.