Hitachi Vantara Pentaho Community Forums
Results 1 to 14 of 14

Thread: How to pass a variable and increment it without using User Defined Java Class

  1. #1

    Default How to pass a variable and increment it without using User Defined Java Class

    Hi,

    I would like to know if it's possible to pass a variable/parameter, increment it ("var=var+1"), and get it in the following step, without using User Defined Java Class step, without using any code for this increment.

    Thanks in advance!

  2. #2
    Join Date
    Nov 2013
    Posts
    1

    Default

    Hi Peptaho,

    All steps in a transformation receive the same set of variables at the initialization phase of a transformation, so there's nothing built-in that allows one step to retrieve a variable, modify it, and then have it update all other steps in the same transformation.

    I believe I've seen an instance where someone did use a UDJC class to do this, but I wouldn't recommend it as a good solution. For one it makes it hard to audit that it's working correctly during testing, as it's a modification done "behind-the-scenes" compared to other techniques.

    Instead, you might just want to use the "Get Variables" step, and then use a Calculator step to perform the increment. This will pass the value as a field within data rows, which would pass it just fine to all other downstream steps.

  3. #3

    Default

    Hi mtucker!

    And thank you very much for your answer! I will have a look to this option!

    Kind regards!

  4. #4
    Join Date
    Sep 2011
    Posts
    152

    Default

    You can do this in JOB but not in transformation.

    In job you can define the variable in the same job and increment that variable in the same job by using that variable.

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

    Default

    As soon as you fully understand the concept Kettle tries to implement, you will hate yourself for incrementing global variables.

    Why not use Add-Sequence and let the dataflow engine do the counting?
    So long, and thanks for all the fish.

  6. #6

    Default

    Quote Originally Posted by marabu View Post
    As soon as you fully understand the concept Kettle tries to implement, you will hate yourself for incrementing global variables.

    Why not use Add-Sequence and let the dataflow engine do the counting?
    Thanks for your answer marabú!

    Do you mean "Add value fields changing sequence"?

    The pioint is that the final objective is to implement a dataflow for classify different attachments. I´m wondering about which will be the best method in order to identify and link every attachment (or attachments) with every email. Maybe storing them in different folders (creating the folders incrementaly), or maybe adding some "sequence" unique number that identify it.

    Any particular suggestion?

    Thanks in advance!

  7. #7

    Default

    Quote Originally Posted by mtucker View Post

    Instead, you might just want to use the "Get Variables" step, and then use a Calculator step to perform the increment. This will pass the value as a field within data rows, which would pass it just fine to all other downstream steps.
    The point is that at Job level I only can use Set Variables (and not Get Variables)

  8. #8
    Join Date
    Sep 2011
    Posts
    152

    Default

    at job level you can also set variable using "Set Variable step" and get the same variable using "Java script" to increment that variable.

  9. #9

    Default

    Quote Originally Posted by rajeshbcrec View Post
    at job level you can also set variable using "Set Variable step" and get the same variable using "Java script" to increment that variable.
    Thank you for your help, rajeshbcrec! I will try to fix it, with one of the options you suggested me!

    Kind regards.

  10. #10

    Default

    Quote Originally Posted by marabu View Post
    As soon as you fully understand the concept Kettle tries to implement, you will hate yourself for incrementing global variables.

    Why not use Add-Sequence and let the dataflow engine do the counting?
    Hi Marabú,

    I´m trying to arrange my transformation with the "Add value fields changing sequence" step, and I don´t know why but something is going wrong...cannot do the increment fixing "start at value" =1 & "Increment by" =1. I create a csv as a summary report, and "result" column is always 1...Attachment 18754Attachment 18754Attachment 18754Attachment 18754Attachment 18754Name:  att1.PNG
Views: 422
Size:  7.7 KB

    Thanks in advance!

  11. #11
    Join Date
    Sep 2011
    Posts
    152

    Default

    all attachments are not visible.

    If the message number field is always unique then "result" is will be always 1.

  12. #12
    Join Date
    Nov 2013
    Posts
    382

    Default

    Why don't you keep stating the real problem as you started to do (in another thread) ?

    As far as I understand you want to get some mails and save each one on a diferent folder. Cannot see any direct way to do it, maybe you could think of a diferent process storing all mails on the same folder, but if you cannot afford for this, try setting a variable with the current date+time up to the millisecond, get just one mail and loop. Adjust your job schedule and number of iterations according to your expected input emalis. You can use a variable on the folder specification.

    Honestly speaking, it's a solution I would never use but it will work ...

  13. #13

    Default

    Quote Originally Posted by DepButi View Post
    Why don't you keep stating the real problem as you started to do (in another thread) ?
    Yes DepButi, it´s what I will do, probably...

    Quote Originally Posted by DepButi View Post
    As far as I understand you want to get some mails and save each one on a diferent folder. Cannot see any direct way to do it, maybe you could think of a diferent process storing all mails on the same folder, but if you cannot afford for this, try setting a variable with the current date+time up to the millisecond, get just one mail and loop. Adjust your job schedule and number of iterations according to your expected input emalis. You can use a variable on the folder specification.
    Yes, I will fix it using a different set of folders, and distributing them (pending, processed, not processed), also controlling the mail number and looping the process.

    Quote Originally Posted by DepButi View Post
    Honestly speaking, it's a solution I would never use but it will work ...
    Thank you very much for your suggestion DepButi! I really appreciate your help, believe me Hopefuly it will work, yes! Thanks again!

  14. #14

    Default

    Quote Originally Posted by rajeshbcrec View Post
    all attachments are not visible.

    If the message number field is always unique then "result" is will be always 1.
    Thanks rajeshcrec! So which field will be incremented then?

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.