rusackas commented on code in PR #43013:
URL: https://github.com/apache/superset/pull/43013#discussion_r3754681108
##########
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:
Good catch — fixed by canonicalizing `Date` keys to their epoch time in
`groupByValue` so identical timestamps from separately-parsed `Date` instances
still land in the same group, while `null` and `'null'` stay distinct. Added a
regression test.
--
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]