Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: Add value fields chang. sequence without increment (or increment only on change value

  1. #1

    Default Add value fields chang. sequence without increment (or increment only on change value

    Hi friends!

    Any easy way to implement this? Perhaps a different trick?

    seq
    fieldvalue1 1
    fieldvalue1 1
    fieldvalue2 2
    fieldvalue2 2
    fieldvalue2 2
    fieldvalue3 3

    I need some way of doing it dynamically, without specifically naming any value


    Thanks!

  2. #2
    Join Date
    Apr 2008
    Posts
    4,684

    Default

    Off the top of my head, this looks like one of the rare cases where javascript might work.

    Set a startup script in the start script to initialize the sequence variable to 0, and a lastseenfield variable to ""

    In your running script, do (pseudo-code!):
    Code:
    if not(field.equals(lastseenfield)) {
        sequence++
        lastseenfield=field
    }

  3. #3

    Default

    Quote Originally Posted by gutlez View Post
    Off the top of my head, this looks like one of the rare cases where javascript might work.

    Set a startup script in the start script to initialize the sequence variable to 0, and a lastseenfield variable to ""

    In your running script, do (pseudo-code!):
    Code:
    if not(field.equals(lastseenfield)) {
        sequence++
        lastseenfield=field
    }
    Thanks!
    Do you mean seting an environtment var?
    By the way, can I make a reference to the "lastrow" in JS?

  4. #4
    Join Date
    Apr 2008
    Posts
    4,684

    Default

    Nope - I mean a Javascript variable.

    I don't believe that you can reference the previous row in Javascript.

    You can put two scripts in one Javascript step, one that is a startup script, and one that gets executed for each row that comes by.
    In your startup script, you can say:
    Code:
    var sequence=0;
    var lastseenfield="";
    and then the other script as the execute per row.
    On the first row, the field won't match lastseenfield, so sequence will be incremented to 1, and lastseenfield will be set to the incoming field value.

    When the script completes and the variables are exported to the outgoing row, sequence will be 1.
    On the next row, the field will match lastseenfield, so nothing will change, and sequence will remain 1.
    **THIS IS A SIGNATURE - IT GETS POSTED ON (ALMOST) EVERY POST**
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

  5. #5
    Join Date
    Apr 2008
    Posts
    4,684

    Default

    Based on your post on the other thread, I think you should *REALLY* look at the Combination Lookup/Update step. It requires a database table to store the key values in, but does exactly what you are asking for, *AND* handles them when they are out of order:

    field sequence (key)
    fieldvalue1 1
    fieldvalue3 3
    fieldvalue2 2
    fieldvalue1 1
    fieldvalue2 2
    **THIS IS A SIGNATURE - IT GETS POSTED ON (ALMOST) EVERY POST**
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

  6. #6

    Default

    Are you sure it is a good idea to rely on a new connection, a particular table created to mock the creation of a key.. i would like to do it in runtime in the ETL

    If only adding sequence on change value step implemented increment in 2 fashions...

    -intervalue increment: 1
    -intravalue increment: 0

    That'd solve my needs

  7. #7

    Default

    Quote Originally Posted by bizintreader View Post
    Are you sure it is a good idea to rely on a new connection, a particular table created to mock the creation of a key.. i would like to do it in runtime in the ETL

    If only adding sequence on change value step implemented increment in 2 fashions...

    -intervalue increment: 1
    -intravalue increment: 0

    That'd solve my needs

    Ok I used the solution kindly provided by you.
    Simply as a JS value step like this really.

    var i=(!i)?0:i;
    var prev;

    if (!Col1.equals(prev)) i++;
    prev = Col1;


    It expects the input sorted by the field for which to generate de ID
    It also breaks on null values for the field (as it is acting like some kind of key), that is purposedly on my script but you can change it simply parsing the variable as I did on var i.

    Thank you for providing me that solution!

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.