Andong Zhan created ARROW-6575:
----------------------------------
Summary: [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
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(1).toString()).toBe('1000000000000000000000000000000000000');
expect(vector.get(0).toString()).toBe('-1000000000000000000000000000000000000');
{code}
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.2#803003)