Skip to content

Fix precision loss for large integers in query results#7645

Open
nmosafi wants to merge 5 commits intogetredash:masterfrom
nmosafi:fix-bigint-precision-loss
Open

Fix precision loss for large integers in query results#7645
nmosafi wants to merge 5 commits intogetredash:masterfrom
nmosafi:fix-bigint-precision-loss

Conversation

@nmosafi
Copy link
Copy Markdown
Contributor

@nmosafi nmosafi commented Feb 25, 2026

Summary

  • Integers exceeding JavaScript's Number.MAX_SAFE_INTEGER (2^53 - 1) lose precision when parsed by JSON.parse() in the browser. For example, a bigint value of 1771858801316128013 would display as 1771858801316128000.
  • The backend json_dumps now converts unsafe integers to strings during serialization, preserving their exact values. The column type remains "integer" so the frontend can still treat the column as numeric for display purposes.
  • The frontend type-sniffing logic in query-result.js now recognises string values that represent large integers in "integer" columns and skips re-typing them as "string".
  • The number formatter in value-format.tsx guards against converting such strings back to JavaScript Numbers via the numeral library.

Test plan

  • Backend unit tests pass (tests/utils/test_json_dumps.py)
  • Verify large integer columns (e.g. Trino BIGINT) display exact values in table visualization
  • Verify safe integers (within MAX_SAFE_INTEGER) are unaffected
  • Verify number formatting still works for normal numeric columns
  • Verify NaN/Inf sanitization is unaffected

🤖 Generated with Claude Code

Integers exceeding JavaScript's Number.MAX_SAFE_INTEGER (2^53-1) are
converted to strings during JSON serialization to preserve their exact
values.  The backend column type stays "integer" so the frontend can
still treat the column as numeric for display purposes.

On the frontend, the type-sniffing logic now recognises string values
that represent large integers in "integer" columns and skips re-typing
them as "string".  The number formatter also guards against converting
such strings back to JavaScript Numbers via numeral.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

nmosafi and others added 3 commits February 25, 2026 17:46
The round-trip check (String(Number(value)) !== value) missed values
that are exactly representable as float64 but still exceed
MAX_SAFE_INTEGER.  The numeral library's internal arithmetic can
introduce drift for these values (e.g. 1772031600000261600 formatted
as 1,772,031,600,000,261,632).

Use Number.isSafeInteger() instead, which correctly catches all
integers beyond 2^53-1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yoshiokatsuneo
Copy link
Copy Markdown
Contributor

I see this as a valid issue.
At the same time, I'm not sure whether we should handle the case or not, as it looks minor case and the PR may makes the code a bit less simple.

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.

2 participants