Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: javascript -- trouble with data types

  1. #1
    Join Date
    Oct 2007
    Posts
    255

    Default [solved] javascript -- trouble with data types

    Original question is listed below, followed by the solution.

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    I am having a bit of trouble with the javascript step. I'm attempting to read values from the previous row to fill-in holes on the current row. When I run the following script, I get exceptions for the final bit where entries in newrow are modified:

    Code:
    var prevrow;
    
    if (missing == null) {
      Alert("missing is null");
    }
    
    if (prevrow == null)
    {
      prevrow = createRowCopy(getOutputRowMeta().size());
      putRow(prevrow);
    }
    else
    {
      if (unixtime != null)
      {
        prevrow = createRowCopy(getOutputRowMeta().size());
        putRow(prevrow);
      }
      else
      {
        prevrow[0]  = prevrow[0] + 60;
        prevrow[4]  = prevrow[0] + 60;
        prevrow[5]  = prevrow[6];
        prevrow[7]  = 0;
        prevrow[8]  = prevrow[9];
        prevrow[10] = 0;
        prevrow[11] = prevrow[6];
        prevrow[12] = prevrow[6];
        prevrow[13] = 0;
        prevrow[14] = 0;
        prevrow[15] = 0;
        prevrow[16] = 0;
        prevrow[17] = 0;
        prevrow[18] = 0;
    
        putRow(prevrow);
      }
    }
    
    trans_Status = SKIP_TRANSFORMATION;
    Among others, the first 2 lines, and the 15th field in prevrow, are what gets errors. this field is an integer, and I get errors attempting to convert the 'float/double' value 0.0 to an integer field.

    The first two fields in the row that are modified in the above are also integers, representing time / date in unixtime format, and I see similar exceptions generated when that block of code executes.

    -Brian


    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    Solution: When writing to integer fields, counter-intuitively you must use the java.lang.Long datatype.

    -Brian
    Last edited by Phantal; 07-29-2009 at 09:32 AM. Reason: solved

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

    Default

    Sorry Brian, that's JavaScript for ya.

    The only workarounds possible is force the data type through Java code ...

    Code:
    var someInt = Packages.java.lang.Math.round(someFloat);
    ... or avoid using JavaScript at all. You can get your hands on previous rows with the "Analytical Query" step these days, etc. So I don't think you actually need JavaScript here.

  3. #3
    Join Date
    Oct 2007
    Posts
    255

    Default asdf

    Matt,

    Unfortunately, where the analytic query only allows you to lag a static number of rows, it won't do what I need. I might have a 20 minute gap here, a 1 minute gap somewhere else, and no gap for another 4 days.

    I'll try the 'round' thing & see where that gets me.

    -Brian

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.