Skip to content

fix: convert BigInt to strings in Arrow IPC row.toJSON()#315

Closed
jamesbroadhead wants to merge 3 commits intomainfrom
fix/bigint-arrow-serialization
Closed

fix: convert BigInt to strings in Arrow IPC row.toJSON()#315
jamesbroadhead wants to merge 3 commits intomainfrom
fix/bigint-arrow-serialization

Conversation

@jamesbroadhead
Copy link
Copy Markdown
Contributor

Summary

  • row.toJSON() from apache-arrow preserves BigInt for Int64 columns. When this data is later serialized with JSON.stringify() for SSE streaming, it throws TypeError: Do not know how to serialize a BigInt.
  • Convert BigInt values to strings in _transformArrowAttachment during row transformation, before the data reaches JSON serialization.
  • This ensures Arrow IPC deserialization works correctly for serverless warehouses that return inline results as Arrow IPC in result.attachment.

Test plan

  • Verify that queries returning Int64 columns via Arrow IPC attachment no longer throw TypeError: Do not know how to serialize a BigInt during SSE streaming
  • Verify that non-BigInt columns are unaffected by the change
  • Verify that the string representation of BigInt values is correct and usable downstream

Replaces #270 (fork-based PR where CI couldn't run).

This pull request was AI-assisted by Isaac.

Co-authored-by: Isaac
Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
The Arrow IPC handling code in this PR imports apache-arrow from
packages/appkit/src/connectors/sql-warehouse/client.ts. Until now
it resolved transitively via packages/appkit-ui, which knip flags
as an unlisted dependency. Declare it directly to satisfy knip
and make the dependency explicit.

Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
@jamesbroadhead jamesbroadhead force-pushed the fix/bigint-arrow-serialization branch from 416c654 to 9c9e409 Compare April 27, 2026 17:30
The previous commit added _transformArrowAttachment but never called it,
so serverless-warehouse responses with inline ARROW_STREAM attachments
still hit the EXTERNAL_LINKS branch and dropped the data.

- Dispatch _transformDataArray to _transformArrowAttachment whenever
  result.attachment is present, before the legacy ARROW_STREAM check.
- Replace the shallow top-level BigInt scan with deepStringifyBigInts,
  which also recurses into nested objects, plain arrays, and Apache
  Arrow Vectors (which row.toJSON() leaves in place for LIST columns).
  Vectors are unwrapped via Array.from so we don't end up with a
  BigInt64Array that would re-throw on bigint -> string assignment.
- Wrap tableFromIPC in try/catch and surface decode failures as a
  bounded ExecutionError with context, instead of an opaque throw from
  inside apache-arrow.
- Make the destructure of response.result tolerant of an undefined
  result rather than throwing TypeError.

Adds a unit test suite covering the inline-Arrow path with BigInt
columns, list-of-bigint columns, the malformed-attachment error case,
the EXTERNAL_LINKS fall-through, and a JSON_ARRAY no-regression check.

Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
@jamesbroadhead
Copy link
Copy Markdown
Contributor Author

Closing — superseded by #256.

The architectural change in #256 moved Arrow IPC decoding from server-side to client-side: the SQL warehouse connector now passes the base64 attachment through unchanged (with a 64MiB size cap), and the React hook decodes via the existing ArrowClient.processArrowBuffer pipeline. Apache Arrow JS in the browser handles BigInt natively, and there is no JSON.stringify in the data path on either side anymore — so the BigInt-vs-JSON.stringify failure mode this PR addressed no longer exists in #256.

Closing without merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant