no-hup opened a new pull request, #43549:
URL: https://github.com/apache/superset/pull/43549

   ### SUMMARY
   The memory formatter (`createMemoryFormatter` in `@superset-ui/core`) breaks 
on two edge ranges:
   
   - For values between 0 and 1 byte, the suffix index 
`Math.floor(Math.log(absValue) / Math.log(base))` goes negative, so 
`suffixes[i]` is `undefined`. `formatter(0.5)` returns `500undefined` instead 
of `0.5B` (negative fractions too: `-0.25` -> `-250undefined`).
   - For values that round up to the base, e.g. `999999` with the default 2 
decimals, the scaled value `999.999` rounds to `1000.00` and the output is 
`1000kB` instead of `1MB`. Binary mode has the same problem near 1024.
   
   This PR clamps the suffix index at 0 (sub-byte values stay in bytes) and, 
when the rounded value reaches the base, bumps to the next unit and rescales. 
The largest unit is left as-is since there is nothing to roll over into. Added 
unit tests for both cases.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A (formatter output only). Before/after:
   
   | input | before | after |
   |---|---|---|
   | `0.5` | `500undefined` | `0.5B` |
   | `-0.25` | `-250undefined` | `-0.25B` |
   | `999999` | `1000kB` | `1MB` |
   | `1024 * 1024 - 1` (binary) | `1024KiB` | `1MiB` |
   
   ### TESTING INSTRUCTIONS
   From `superset-frontend/`:
   
   ```
   npm run test -- 
packages/superset-ui-core/test/number-format/factories/createMemoryFormatter.test.ts
   ```
   
   All 10 tests pass (8 existing + 2 new). You can also reproduce the old 
behavior on master with `createMemoryFormatter()(0.5)`.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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]

Reply via email to