Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Clarification of FAQ needed

  1. #1

    Default Clarification of FAQ needed

    In entry 5.9.4 of the FAQ (How to create a new row), it is described how to add a new row to the stream, like so:

    Code:
    var newRow = row.Clone(); // make a copy
    // modify newRow
    _step_.putRow(newRow); // sends an extra row on the output of the step
    Now that I have the variable newRow point to my new row, how do I change a specific field from newRow? I couldn't construct that bit of information from the other FAQ entries.

    It looks like setValue() is used on fields, and there is row.getValue(index), but I miss something like row.setValue(index, value) or similar.

    Thanks,
    Tobias

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    With getValue() you get a reference back, change that and the "original" changes.

    And there's also a "void setValue(int idx, Value v)" method available in 2.5.

    In 3.0 it becomes easier or trickier depending on which direction you come from... in 3.0 row is just Object[] (if you turn compatibility off).

    Regards,
    Sven

  3. #3

    Default

    Hi

    Using setValue(), I can get it to work. Using a reference, I can't, I must be doing something wrong. See attached transformation.

    Thanks,
    Tobias
    Attached Files Attached Files

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    which version... 3.0?

    Regards,
    Sven

  5. #5

    Default

    Nope, 2.5.1

  6. #6
    Join Date
    May 2006
    Posts
    4,882

    Default

    Well, you get the value by reference (in 2.5.1). So do the following:

    Code:
    // try with reference, does work
    index1 = newRow.searchValueIndex("change_by_reference");
    value1 = newRow.getValue(index1); // val is now a reference
    value1.setValue(7.00);
    If you just assign a value to value1 it will overwrite the reference.

    2 notes:
    - the code above currently does not work in in 3.0.0-M2 (there's a tracker for it raised)
    - not related to the above but you get 2 output rows in the java modified script if you do a putrow yourself.

    Regards,
    Sven

  7. #7

    Default

    Quote Originally Posted by sboden View Post
    If you just assign a value to value1 it will overwrite the reference.
    Right, of course. Thanks!

    Quote Originally Posted by sboden View Post
    - not related to the above but you get 2 output rows in the java modified script if you do a putrow yourself.
    That's what I want to do. The abstracted scenario here is:

    I have rows with a date, starttime and endtime. It can be that endtime is past midnight. In that case, I want to have the enddate of the existing row set to 23:59:59, and add a new row with startdate=00:00 and the actual enddate.

    Everything is working nicely now.

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.