Copilot commented on code in PR #43013:
URL: https://github.com/apache/superset/pull/43013#discussion_r3754030645
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/treeBuilder.ts:
##########
@@ -31,6 +30,30 @@ function getMetricValue(datum: DataRecord, metric: string) {
return typeof datum[metric] === 'number' ? (datum[metric] as number) : 0;
}
+// Groups records by the raw value of `groupByKey`, keyed with a Map instead
+// of a plain object. A plain-object accumulator (e.g. lodash's `groupBy`)
+// has to coerce every key to a string to use it as a property name, so a SQL
+// NULL and the literal string "null" both collapse to the same "null" key
+// and get merged into a single group. A Map keeps them as distinct keys, so
+// null filtering stays deterministic regardless of what else is in the
+// column.
+function groupByValue(
+ data: DataRecord[],
+ groupByKey: string,
+): Map<DataRecordValue, DataRecord[]> {
+ const groups = new Map<DataRecordValue, DataRecord[]>();
+ data.forEach(datum => {
+ const key = datum[groupByKey];
+ const group = groups.get(key);
+ if (group) {
+ group.push(datum);
+ } else {
+ groups.set(key, [datum]);
+ }
+ });
Review Comment:
`groupByValue` uses the raw `DataRecordValue` as a `Map` key. This fixes
`null` vs `'null'`, but it changes grouping semantics for `Date` values: `Map`
compares `Date` keys by object identity, so two different `Date` instances
representing the same timestamp will end up in different groups. Since
`DataRecordValue` explicitly allows `Date`, and callers format temporal values
via `formatSeriesName(...)`, this can produce duplicated nodes and incorrect
rollups for temporal group-bys.
Consider canonicalizing `Date` keys inside `groupByValue` so identical
timestamps share the same key instance (while still keeping `null` and `'null'`
distinct).
--
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]