wgzhao commented on PR #62129:
URL: https://github.com/apache/doris/pull/62129#issuecomment-4190217091
> 1. What problem was fixed (it's best to include specific error reporting
information). How it was fixed.
The primary problem fixed was the **loss of precision for large integers
(`bigint`)** when displaying data within the table component.
The system exhibited faulty behavior where large numbers, such as
`2040824788225757185`, were being coerced into standard JavaScript `Number`
types during rendering. This coercion causes any integer exceeding $2^{53} - 1$
(the safe limit for JavaScript `Number`) to lose its trailing digits, resulting
in an incorrect display value (e.g., `2040824788225757200`). This was triggered
by rendering the numeric data fields (`tdData`) directly in the JSX.
The fix involves adding a type and range check within the table rendering
loop. Before displaying the content of any table cell (`tdData`), we check if
it is a `number` *and* if its absolute value exceeds `Number.MAX_SAFE_INTEGER`.
If both conditions are true, we explicitly convert the number to its string
representation using `String(tdData)`. This ensures that the full, precise
value of the large integer is passed to React's rendering engine as a string,
bypassing the lossy number coercion.
> 2. Which behaviors were modified. What was the previous behavior, what is
it now, why was it modified, and what possible impacts might there be.
* **Previous Behavior:** Large numbers greater than $2^{53} - 1$ displayed
an incorrect, rounded, or truncated value due to implicit JavaScript `Number`
type conversion during rendering.
* **New Behavior:** The same large numbers are now displayed with their
full, correct digits, maintaining the precision expected from a `bigint`.
* **Why modified?** The modification is necessary to correct data
integrity displayed to the user. We modified the rendering logic to
preemptively cast these specific numbers to strings to prevent data loss.
* **Possible Impacts:** The only potential impact is that if the consuming
code *expects* the cell content to always be a number type (and attempts
arithmetic operations on it after rendering), it might encounter a `TypeError`
because the value is now reliably a string. However, given the nature of
displaying IDs/results, string interpretation is the safest assumption.
> 3. What features were added. Why was this function added?
No entirely new features were added. The functionality remains displaying
table data, but the robustness of the data type handling for large numbers is
an added quality enhancement.
> 4. Which code was refactored and why was this part of the code refactored?
The rendering logic within the component responsible for iterating over
`tableData` (the inner `.map()` loop for rendering `<td>` elements) was
refactored. This refactoring was necessary to introduce the type-checking and
explicit string casting logic described above, isolating the data type handling
for large integers.
> 5. Which functions were optimized and what is the difference before and
after the optimization?
This PR is primarily a **bug fix/correctness improvement**, not a pure
performance optimization. However, the addition of the `if/else if` structure
improves the **correctness** of the rendering process by guaranteeing type
safety for the problematic data path. Before, the code was susceptible to
silent data corruption; after, it correctly handles the transition from
potentially imprecise number types to reliable string display types.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]