-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(number-format): adds memory data transfer rates in binary and decimal format #32264
feat(number-format): adds memory data transfer rates in binary and decimal format #32264
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Uncached D3 Formatter Creation ▹ view | ✅ | |
Redundant Break After Return ▹ view | ✅ | |
Incorrect Zero Value Formatting ▹ view | ✅ | |
Format description inconsistencies ▹ view | ✅ | |
Invalid format patterns for network data formatting ▹ view | ✅ |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/packages/superset-ui-core/src/number-format/index.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/NumberFormats.ts | ✅ |
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts | ✅ |
superset-frontend/src/setup/setupFormatters.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts | ✅ |
superset-frontend/src/explore/controls.jsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
superset-frontend/packages/superset-ui-core/src/number-format/NumberFormats.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/korbit-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Uncaught d3Format Error ▹ view | ✅ | |
Inconsistent small number formatting ▹ view | ✅ | |
Missing bounds check for large values ▹ view | ✅ | |
Missing Closing Parentheses ▹ view | ✅ | |
Missing Closing Parenthesis ▹ view | ✅ |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/packages/superset-ui-core/src/number-format/index.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/NumberFormats.ts | ✅ |
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts | ✅ |
superset-frontend/src/setup/setupFormatters.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts | ✅ |
superset-frontend/src/explore/controls.jsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts
Outdated
Show resolved
Hide resolved
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts
Outdated
Show resolved
Hide resolved
/korbit-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Unbounded Cache Growth ▹ view | ✅ | |
Stack trace lost in error re-throw ▹ view | ✅ | |
Missing Type Safety for Labels Parameter ▹ view | ✅ | |
Invalid siFormatter Parameter for Microsecond Values ▹ view | ✅ |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/packages/superset-ui-core/src/number-format/index.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/NumberFormats.ts | ✅ |
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts | ✅ |
superset-frontend/src/setup/setupFormatters.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts | ✅ |
superset-frontend/src/explore/controls.jsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
/korbit-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Inefficient Small Number Formatting Strategy ▹ view | ✅ | |
Unsafe cache key access ▹ view | ✅ | |
Incorrect Unit Notation in Format Descriptions ▹ view |
Files scanned
File Path | Reviewed |
---|---|
superset-frontend/packages/superset-ui-core/src/number-format/index.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/NumberFormats.ts | ✅ |
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts | ✅ |
superset-frontend/src/setup/setupFormatters.ts | ✅ |
superset-frontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts | ✅ |
superset-frontend/src/explore/controls.jsx | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Feedback and Support
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
...ontend/packages/superset-ui-core/src/number-format/factories/createNetworkNumberFormatter.ts
Outdated
Show resolved
Hide resolved
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff, I'm sure this will be valuable to many orgs! First pass comments.
const bytesSILabels = ['Bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']; | ||
const bytesIECLabels = [ | ||
'Bytes', | ||
'KiB', | ||
'MiB', | ||
'GiB', | ||
'TiB', | ||
'PiB', | ||
'EiB', | ||
'ZiB', | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there overlap here with the code in createMemoryFormatter.ts
? I think ideally we want to avoid duplication and double down on the same terms. Some quick observations:
- Here we're talking about
Bytes
, while in memory formatter we haveB
- Here we're only going to
ZiB
/ZB
, while in memory formatter we're going all the way toYiB
and for SI toQB
.
const byterateSILabels = [ | ||
'Bytes/s', | ||
'kB/s', | ||
'MB/s', | ||
'GB/s', | ||
'TB/s', | ||
'PB/s', | ||
'EB/s', | ||
'ZB/s', | ||
]; | ||
const byterateIECLabels = [ | ||
'Bytes/s', | ||
'KiB/s', | ||
'MiB/s', | ||
'GiB/s', | ||
'TiB/s', | ||
'PiB/s', | ||
'EiB/s', | ||
'ZiB/s', | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplication, can we just use the bytes above and then slap on a /s
after them?
function siFormatter(decimals: number) { | ||
if (formatterCache.size >= MAX_CACHE_SIZE) { | ||
const iterator = formatterCache.keys(); | ||
const first = iterator.next(); | ||
if (!first.done) { | ||
formatterCache.delete(first.value); | ||
} | ||
} | ||
|
||
try { | ||
if (!formatterCache.has(decimals)) { | ||
formatterCache.set(decimals, d3Format(`.${decimals}s`)); | ||
} | ||
return formatterCache.get(decimals); | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to create SI formatter for ${decimals} decimals: ${error.message}`, | ||
{ cause: error }, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this performance optimization needed? Was there performance issues without this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this was to satisfy the korbit-ai review bot 😅 if you don't think it's really needed I can simplify it back to its original form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry about our house bot giving you bad advice 🤦 Yes, please roll this back, I didn't quite understand how it would help in this context. So let's keep it simple and add memoization later if it's really needed.
function formatValue( | ||
value: number, | ||
labels: string[], | ||
base: number, | ||
decimals: number, | ||
) { | ||
if (value === 0) { | ||
return `0 ${labels[0]}`; | ||
} | ||
const absoluteValue = Math.abs(value); | ||
if (absoluteValue >= 1000) { | ||
const i = Math.min( | ||
Math.floor(Math.log(absoluteValue) / Math.log(base)), | ||
labels.length - 1, | ||
); | ||
const parsedVal = parseFloat( | ||
(absoluteValue / Math.pow(base, i)).toFixed(decimals), | ||
); | ||
return `${value < 0 ? '-' : ''}${parsedVal} ${labels[i]}`; | ||
} | ||
if (absoluteValue >= 1) { | ||
return `${float2PointFormatter(value)} ${labels[0]}`; | ||
} | ||
if (absoluteValue >= 0.001) { | ||
return `${float4PointFormatter(value)} ${labels[0]}`; | ||
} | ||
if (absoluteValue > 0.000001) { | ||
return `${siFormatter(decimals)(value * 1000000)}µ ${labels[0]}`; | ||
} | ||
return `${float4PointFormatter(value)} ${labels[0]}`; | ||
} | ||
|
||
function formatBytesSI(value: number, decimals: number) { | ||
return formatValue(value, bytesSILabels, 1000, decimals); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a fair amount of logic here that we'd want to have unit tests for. Can we add those to get full test coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I'm still in the process of figuring out how to run tests from my dev container, once I get that running I'll see about getting coverage on all new branches
I think this approach is great, but I also wonder if you're aware of the Advanced Types feature. It's a bit lesser-known, but this might be an interesting application for it. The original implementation of it was to match different formats of IP addresses to one another (acting as a bit of a translation layer, if you will). Having a "fille size" type might allow you to match data where columns contain different units, and do the appropriate conversions, e.g. 1000KB = 1MiB, or 1024K = 1MB, etc. Here's the original SIP that explains it better than I'm doing :) |
re-running CI 🤞 |
Sorry for the delayed update on the PR: @rusackas we weren't able to get advanced types to work for our particular use case, so I took the comments and revisited the code change. It's still a work in progress but I think the best approach is to simply add an extra config to so the final
This way we heavily re-use the createMemoryFormatter and simplify things a bit. @villebro Thoughts? |
Thanks for staying on top of this! Re-running CI 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, LGTM!
SUMMARY
At Yahoo we needed custom number formatters for data transfer rates, in either IEC or Standard format (binary or decimal). This change adds the following NumberFormats:
Where decimal records rates in terms of gigabyte, terabyte, and petabytes, and binary records rates in terms of gibibytes, tebibytes, and pebibytes. The number formatter expects absolute values in bytes.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
123456789
MEMORY_TRANSFER_RATE_DECIMAL: 123.46 MB/s
MEMORY_TRANSFER_RATE_BINARY (IEC): 117.74 MiB/s
ADDITIONAL INFORMATION