vogievetsky commented on code in PR #20384:
URL: https://github.com/apache/druid/pull/20384#discussion_r4064686646
##########
web-console/src/utils/general.tsx:
##########
@@ -41,6 +41,27 @@ export function isNumberLikeNaN(x: NumberLike): boolean {
return isNaN(Number(x));
}
+/**
+ * Query results and API responses are parsed with JSONBig, so any integer
with 16+ digits arrives
+ * as a BigInt. Charting libraries can not do arithmetic on those, so flatten
them back to numbers.
+ */
+export function bigIntsToNumbers<T extends Record<string, any>>(rows: T[]):
T[] {
+ return rows.map(row => {
+ let changed = false;
+ const res: Record<string, any> = {};
+ for (const k of Object.keys(row)) {
+ const v = row[k];
+ if (typeof v === 'bigint') {
+ res[k] = Number(v);
Review Comment:
Good catch, fixed in 96e50b5186.
`bigIntsToNumbers` now takes an explicit list of measure keys and leaves
every other column untouched, so dimension values keep their exact BigInt:
- bar chart: `["met"]` — `dim` is passed through unchanged, so distinct
categories stay distinct and the click-to-filter `equal(label)` targets the
real value
- pie chart: `["value"]` — `name` is already `CAST(... AS VARCHAR)`, so it
was never at risk
- multi-axis chart: `measures.map(m => m.name)` — the time column and
anything else are left alone
##########
web-console/src/views/datasources-view/datasources-view.tsx:
##########
@@ -1273,13 +1285,15 @@ GROUP BY 1, 2`;
{pluralIfNeeded(num_segments, 'segment')}
</a>
);
+ if (typeof num_segments_to_load !== 'number' || typeof
num_segments !== 'number') {
Review Comment:
Agreed, fixed in 96e50b5186.
This guard predates the PR, but the accessor change made it inconsistent —
the same fields were being normalized for sorting and then rejected for
display. The root problem was that `DatasourceQueryResultRow` declared these
counts as `number`, which is exactly the "type lies" case the rest of the PR is
about, so:
- widened `num_segments`, `num_zero_replica_segments`,
`num_segments_to_load`, `num_segments_to_drop` and the granularity counts to
`NumberLike`
- the guard is now `isNumberLike(...)`, so it still returns `-` for
genuinely absent data (`undefined`/`null`) but accepts BigInt
- `numSegments` / `numSegmentsToLoad` are coerced once and used for every
division and comparison below, including the `num_zero_replica_segments`
equality check that would otherwise mix a BigInt with a Number
--
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]