From f9db33875cd2086fc4d5b05d849fbecba8b7d66a Mon Sep 17 00:00:00 2001 From: Gabe Gorelick Date: Fri, 25 Oct 2024 17:09:24 -0400 Subject: [PATCH] Don't truncate BigInts BigInts are currently converted to JS Numbers, which can't fit values over 2**53. Fixes #259 --- lib/result/ArrowResultConverter.ts | 2 +- lib/result/utils.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/result/ArrowResultConverter.ts b/lib/result/ArrowResultConverter.ts index 57fa02a..b4f36fe 100644 --- a/lib/result/ArrowResultConverter.ts +++ b/lib/result/ArrowResultConverter.ts @@ -205,7 +205,7 @@ export default class ArrowResultConverter implements IResultsProvider } // Return other values as is - return typeof value === 'bigint' ? Number(value) : value; + return value; } private convertThriftTypes(record: Record): any { diff --git a/lib/result/utils.ts b/lib/result/utils.ts index 4bbdf41..47de835 100644 --- a/lib/result/utils.ts +++ b/lib/result/utils.ts @@ -49,12 +49,11 @@ function convertJSON(value: any, defaultValue: any): any { } function convertBigInt(value: any): any { - if (typeof value === 'bigint') { - return Number(value); - } if (value instanceof Int64) { - return value.toNumber(); + return BigInt(value.toString()); } + + // Do not convert a BigInt away from the BigInt type return value; }