Skip to content

Commit f3cf83f

Browse files
committed
fix: correct parsing of nullable bigint columns
1 parent 8862ddb commit f3cf83f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/statement/hydrateResponse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const getHydratedValue = (
4949
type: string,
5050
executeQueryOptions: ExecuteQueryOptions
5151
): any => {
52+
// strip null to ensure correct type checking in the following steps
53+
if (type.endsWith("null")) {
54+
type = type.replace("null", "").trim();
55+
}
5256
if (isStructType(type)) {
5357
return hydrateStruct(
5458
value as Record<string, unknown>,

test/integration/v2/fetchTypes.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ describe("test type casting on fetch", () => {
4242
const row = data[0];
4343
expect((row as unknown[])[0]).toEqual(new BigNumber("9223372036854775807"));
4444
});
45+
it("select nullable bigint", async () => {
46+
const firebolt = Firebolt({
47+
apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string
48+
});
49+
// Max value for a signed 64-bit integer (bigint)
50+
const testQuery = `
51+
WITH a AS (
52+
SELECT 9223372036854775807::bigint UNION ALL SELECT null::bigint
53+
)
54+
SELECT * FROM a
55+
`;
56+
const connection = await firebolt.connect(connectionParams);
57+
58+
const statement = await connection.execute(testQuery);
59+
60+
const { data, meta } = await statement.fetchResult();
61+
expect(meta[0].type).toEqual("long null");
62+
const row = data[0];
63+
expect((row as unknown[])[0]).toEqual(new BigNumber("9223372036854775807"));
64+
});
4565
it("select negative bigint", async () => {
4666
const firebolt = Firebolt({
4767
apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string

test/unit/v1/statement.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ describe("parse values", () => {
313313
new BigNumber(1000000000000000000000000000000000000)
314314
);
315315
});
316+
it("parses biging null into BigNumber container", () => {
317+
allure.description("Verify nullable bigint is parsed correctly");
318+
const row = {
319+
big: "1000000000000000000000000000000000000"
320+
};
321+
const meta = [{ name: "big", type: "long null" }];
322+
const res: Record<string, BigNumber> = hydrateRow(row, meta, {});
323+
expect(res["big"] instanceof BigNumber).toBe(true);
324+
expect(res["big"]).toEqual(
325+
new BigNumber(1000000000000000000000000000000000000)
326+
);
327+
});
316328
});
317329

318330
describe("set statements", () => {

0 commit comments

Comments
 (0)