Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: How to add a field/column with a Variable value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. Default How to add a field/column with a Variable value

    I'd like to add a column to the stream (read from a serialized file). The column should contain a constant that is determined by a Variable

    I can't use AddConstants and set the value to ${Var}, as constants really means constant.

    I tried to use JavaScript but don't know how to add a field. Here is my attempt so far
    Code:
    importPackage(org.pentaho.di.core.row);
    
    var r = getVariable("VAR", "");
    var valueMeta = new ValueMeta("r", ValueMetaInterface.INTEGER, 15, 0);
    getInputRowMeta().addValueMeta("r");
    var rowIndex = getInputRowMeta().indexOfValue("r");
    
    row[rowIndex] = r;
    This JavaScript implementation seems not to be able to access the Java packages. What do I do wrong?

    Are there better ways?

    K<o>

  2. #2
    DEinspanjer Guest

    Default

    a constant that is determined by a variable?

    You're going to have to try explaining things again.
    Variables in Kettle transformations are not like a variable in a program or script. They are more like environment variables. Things set before the transformation is run. They can't change dynamically so I don't think that is what you want here.

    If you are reading input from two sources and you want to join them together then you probably want some sort of Join step.

  3. Default

    Hi Daniel,
    Thanks for the reply.

    Variables in Kettle transformations are not like a variable in a program or script. They are more like environment variables. Things set before the transformation is run.
    This is exactly what I want. I have a job that sets the variable in an earlier transformation and I want to add this as a constant (relative to the transformation it is constant). But the AddConstants does not allow me to use an Environment (Kettle) variable as value. It takes it literally as string.

    Is there any better approach than the JavaScript? If not, how do I make it work in JS?

    K<o>

  4. Default Any furhter thoughts?

    Is there any solution to this?

    I tried JavaScript and get no-where, because I can't create a typed value.

    Any other ideas?

  5. #5
    DEinspanjer Guest

    Default

    Sorry I missed this follow-up question.

    Just use the Get Variables step under the Job category.

  6. Default

    Quote Originally Posted by DEinspanjer View Post
    Sorry I missed this follow-up question.
    While I spend hours in the last few days to find a solution and so wished you had answered sooner, I'm certainly glad you answered at all. Thank You!

    Quote Originally Posted by DEinspanjer View Post
    Just use the Get Variables step under the Job category.
    This works fine. In addition I needed the column to be Integer 15/0 so I did a Set Values step right after it.

    K<o>
    P.S.: In my desperation, I even started a project to hack the Add Constants step to allow a variable field in there. Well I learned something along the way.

  7. #7
    Join Date
    Oct 2016
    Posts
    1

    Default the solution works

    Quote Originally Posted by DEinspanjer View Post
    Sorry I missed this follow-up question.

    Just use the Get Variables step under the Job category.

    thanks

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.