Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: javascript and equality/== testing

  1. #1

    Default javascript and equality/== testing

    I've been scratching my head trying to figure out how equality testing works in a Modified Java Script Value step with compatibility mode off. The obvious thing "if (a==b)" just doesn't seem to work as expected.

    In my particular case, my input rows are sorted on an integer field pat_id, and I wanted to use javascript to mark the first row where pat_id changes to a new value. So I declared a variable last_pat_id and tried the obvious thing:

    if (last_pat_id==null || last_pat_id!=pat_id)
    // do something;
    last_pat_id = pat_id;

    That didn't work as expected, because the != test was returning true even when values "seemed" to be equal.

    What I ended up doing was

    if (last_pat_id==null || (last_pat_id-pat_id != 0))
    // do something;
    last_pat_id = pat_id;

    This works, but I'd like to understand if there's a better way, and also in general why ==/!= seem so challenging with compatibility mode off.

    As an aside, as a java programmer one thing I thought to look at was to inspect pat_id.getClass().getName(), but apparently rhino doesn't let you do this. The docs led me to believe pat_id would be a java.lang.Long instance, so I also tried getting its longValue(), but I didn't have any luck with that either.

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    These objects are java objects like Long (in the Integer case).
    They can be null obviously. I would expect these Long objects to be automatically converted by Rhino or the JVM into long.
    However, perhaps you are dealing with BigNumber data types or something of the kind?
    That might make a difference.

  3. #3

    Default

    Kettle describes pat_id as type Integer when I look at Input Fields for the js step.

    I'm assuming the issue is something like typing differences between the script-declared var and the pat_id in the input row. I also tried equals() instead of ==, which I've had some luck with for string comparisons in js steps, but it didn't work here.

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    If you do any calculation with those numbers, please remember that JS has the nasty habit of changing things into doubles.
    Other than that, I don't know what could cause it.

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.