Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Conditional structure between fields

  1. #1

    Default Conditional structure between fields

    Friends,

    At one part of the transformation, I want to create another field where its value will be conditional to compare two other fields. I will give an example to be the easier understanding of my problem. Look ...

    I have the following table:
    COD_RESID COD_ASSIST YEAR NUM_SURGERY
    120040 120040 2015 73
    120038 120040 2015 5
    120060 120040 2015 2
    120001 120040 2015 4

    The 'COD_RESID' field is place of residence of the person, 'COD_ASSIST' is the place where the person had medical assistance and 'NUM_SURGERY' field is the number of surgeries that were performed on people living in the city with 'COD_RESID' code.

    I need to know if the site where the surgery was performed is the same place of residence of the person and thus create a new field called 'COD_DISP' (displacement code) would receive "0" if the 'COD_RESID' was equal to 'COD_ASSIST' and "1" if 'COD_RESID' were different from 'COD_ASSIST'.

    To do this, I inserted in the transformation the step Modified JavaScript Value and wrote the following JavaScript code:

    var COD_DISP; (COD_RESID == COD_ASSIST) ? COD_DISP = 0 : COD_DISP = 1;

    It seemed an easy task, the transformation is completed successfully, but when I will examine the contents of the output of the transformation, there is only the value of the condition when it is false. In my case, only values equal to "1". I've tried several things, but just can not make the condition function properly.

    Does anyone have any idea what I might be doing wrong? And if I'm doing something wrong, how can I make this work correctly?

    Thank you and greetings Brazilian.

  2. #2

    Default

    How about if you add a few lines to your Java Script? For example Alert("COD_DISP is:" + COD_DISP + " and COD_RESID is:" + COD_RESID + " and COD_ASSIST is:" + COD_ASSIST);

    this should tell you the values per each row.

    Hugo

  3. #3

    Default

    Hello Hugo,


    Thanks for your suggestion. It just reinforced my theory that there is some problem with the conditional structure comparing two fields. I took the opportunity to test the comparison of a field, for example, COD_ASSIST with a known existing value <var COD_DISP; COD_ASSIST == 120040 COD_DISP = 0: COD_DISP = 1;> and everything worked perfectly.

    Wisley Velasco

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

    Default

    COD_RESID and COD_ASSIST are Java Objects, so COD_RESID.equals(COD_ASSIST) would be the right way to test equality of String objects.
    People tend to happily code away with the Modified-Java-Script-Value step, but despite the name it's not JavaScript as you know it: It's Rhino, a JavaScript interpreter written in Java. I suggest you read the wiki page on MJSV carefully.

    BTW: If there's nothing else you need JavaScript for I would prefer to use a User-Defined-Java-Expression.
    So long, and thanks for all the fish.

  5. #5

    Default

    Dear Marabu,


    Thank you very much for your help. The comparison between two fields in my ETL is working now. Its orientation was very important.


    Thanks also by clarify technical issues about 'Modified Java Script Value' step works. Knowing these issues helps us better understand how it works and thus make better use of the component. The page suggested by you is already in my favorites to never forget how to use this step.

    By the way, I would like to take the opportunity to also share the alternative way that I found to solve my problem. Thus I leave another solution of choice for people in the future are interested in this topic.

    So I inserted the transformation step 'Formula' and used "if" the Logical category with the following expression:

    IF ([PA_MUNPCN] = [PA_UFMUN], 0, 1)

    It seems the Excel IF function.


    Tks all for helping me.


    Brazilian greetings.

    Wisley Velasco

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.