You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Andong Zhan (Jira)" <ji...@apache.org> on 2019/09/25 17:07:00 UTC

[jira] [Issue Comment Deleted] (ARROW-6575) [JS] decimal toString does not support negative values

     [ https://issues.apache.org/jira/browse/ARROW-6575?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andong Zhan updated ARROW-6575:
-------------------------------
    Comment: was deleted

(was: I will make PR to share our walkaround solution soon.)

> [JS] decimal toString does not support negative values
> ------------------------------------------------------
>
>                 Key: ARROW-6575
>                 URL: https://issues.apache.org/jira/browse/ARROW-6575
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: JavaScript
>    Affects Versions: 0.14.1
>            Reporter: Andong Zhan
>            Priority: Critical
>
> The main description is here: [https://github.com/apache/arrow/issues/5397]
> Also, I have a simple test case (slightly changed generate-test-data.js and generated-data-validators):
> {code:java}
> export const decimal = (length = 2, nullCount = length * 0.2 | 0, scale = 0, precision = 38) => vectorGenerator.visit(new Decimal(scale, precision), length, nullCount);
> function fillDecimal(length: number) {
>     // const BPE = Uint32Array.BYTES_PER_ELEMENT; // 4
>     const array = new Uint32Array(length);
>     // const max = (2 ** (8 * BPE)) - 1;
>     // for (let i = -1; ++i < length; array[i] = rand() * max * (rand() > 0.5 ? -1 : 1));
>     array[0] = 0;
>     array[1] = 1286889712;
>     array[2] = 2218195178;
>     array[3] = 4282345521;
>     array[4] = 0;
>     array[5] = 16004768;
>     array[6] = 3587851993;
>     array[7] = 126217744;
>     return array;
> }
> {code}
> and the expected value should be
> {code:java}
> expect(vector.get(0).toString()).toBe('-1000000000000000000000000000000000000');
> expect(vector.get(1).toString()).toBe('1000000000000000000000000000000000000');
> {code}
> However, the actual first value is 339282366920938463463374607431768211456 which is wrong! The second value is correct by the way.
> I believe the bug is in the function called 
> function decimalToString<T extends BN<BigNumArray>>(a: T) because it cannot return a negative value at all.
> [arrow/js/src/util/bn.ts|https://github.com/apache/arrow/blob/d54425de19b7dbb2764a40355d76d1c785cf64ec/js/src/util/bn.ts#L99]
> Line 99 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)