Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Problem in Database.java - Math.round()

  1. #1

    Default Problem in Database.java - Math.round()

    There seems to be a problem using the Math.round() method. Here's how to replicate ...

    CREATE TABLE `source_testing` (
    `glb_dtime` bigint(16) unsigned NOT NULL default '0',
    `description` varchar(45) default NULL,
    PRIMARY KEY (`glb_dtime`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1


    CREATE TABLE `stage_testing` (
    `glb_dtime` bigint(16) unsigned NOT NULL default '0',
    `description` varchar(45) default NULL,
    PRIMARY KEY (`glb_dtime`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1


    insert into `source_testing`
    values (
    4522787498623415, NULL
    )


    Use a simple transformation, table input -> table output. The target table is populated but with the following value ...
    4522787498623416

    problem seems to lie here in be\ibridge\kettle\core\database\Database.java line 514

    >
    > ps.setLong(pos, Math.round( v.getNumber() ) );
    >

    Changing the code to the following yields the correct value in the target table, however I'm sure this is far from being a desirable solution.

    >
    > Double val = new Double(v.getNumber());
    > ps.setLong(pos, val.longValue() );
    >


    My version of java ...
    java -version
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

  2. #2

    Default RE: Problem in Database.java - Math.round()

    Hi Matt,

    Thanks for the quick response.

    >
    > I guess the precision of the 4522787498623415
    > figure is too big for Number to hold.
    >
    values larger than 4522787498623415 are inserted correctly, e.g. 4522787498623518, however there are others which fail, e.g. 4522787498623515 - 4522787498623517. Your suggestion of using Select Values with the meta-data change works as expected, so I guess not an issue.

    >
    > What database table are you reading from?
    >
    I first noticed the problem when pulling data from an Oracle database and started testing this issue on a MySQL database. Occurs in both.

    >
    > Try to place a Select Values step in between with
    > a meta-data change to BigDecimal.
    >
    works like a charm - thanks

    Regards,

    Greg

  3. #3

    Default RE: Problem in Database.java - Math.round()

    oops, seems I edited your response? Sorry.

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

    Default RE: Problem in Database.java - Math.round()

    Well, the reason I asked about the databases used, is that beyond a certain precision, BigNumber (java BigDecimal) is and should be used to represent the data.

    For Oracle this should be anything over Number(9,x). (Have to check)

    So I will be using your example to test a couple of things, maybe we should switch to BigDecimal earlier.

    Hey, thanks for the feedback!

    Matt

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.