bito-code-review[bot] commented on code in PR #44044:
URL: https://github.com/apache/superset/pull/44044#discussion_r4016654057
##########
superset-frontend/packages/superset-ui-core/src/components/Select/utils.tsx:
##########
@@ -91,16 +91,21 @@ export const propertyComparator =
if (typeof propertyA === 'number' && typeof propertyB === 'number') {
return propertyA - propertyB;
}
- // BIGINT columns can decode to native `bigint` values (see json-bigint
- // parsing of large numeric values). Compare numerically rather than
- // falling through to the string fallback below, which would sort them
- // lexicographically (e.g. "10", "100", "2").
+ // BIGINT columns can decode to native `bigint` values or decimal strings
+ // (see parseResponse.ts). Compare numerically rather than falling through
+ // to the string fallback below, which would sort lexicographically.
if (
- (typeof propertyA === 'bigint' || typeof propertyA === 'number') &&
- (typeof propertyB === 'bigint' || typeof propertyB === 'number')
+ (typeof propertyA === 'bigint' ||
+ typeof propertyA === 'number' ||
+ (typeof propertyA === 'string' && /^-?\d+$/.test(propertyA))) &&
+ (typeof propertyB === 'bigint' ||
+ typeof propertyB === 'number' ||
+ (typeof propertyB === 'string' && /^-?\d+$/.test(propertyB)))
) {
- if (propertyA < propertyB) return -1;
- if (propertyA > propertyB) return 1;
+ const a = Number(propertyA);
+ const b = Number(propertyB);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Precision loss in Number()</b></div>
<div id="fix">
`Number(propertyA)`/`Number(propertyB)` lose precision for values beyond
`Number.MAX_SAFE_INTEGER` (2^53): e.g. `9007199254740993n` and
`9007199254740992n` both coerce to `9007199254740992`, collapsing distinct
values and producing wrong sort order — exactly the large-BIGINT case this
change targets. Use `BigInt()` for bigint and integer-string values to preserve
full precision, but keep `Number()` for the float-number case (since
`BigInt(1.5)` throws a RangeError).
</div>
</div>
<small><i>Code Review Run #169d7c</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]