GroupingToMatrix: Defensively guard against null column name (#99286)

* bugfix: defensive guard against null columnName

* fix: per suggestion limit diff and revert alphabetization of properties

* test: add test for null case

* chore: remove it.only

* test: convert to inline snapshot
This commit is contained in:
Alex Spencer 2025-01-22 09:37:21 -07:00 committed by GitHub
parent a0e7569e4f
commit 29d9d8cf51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 72 additions and 1 deletions

View File

@ -155,6 +155,77 @@ describe('Grouping to Matrix', () => {
});
});
it('properly handles null column name values', async () => {
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
id: DataTransformerID.groupingToMatrix,
options: {
columnField: 'Column',
rowField: 'Row',
valueField: 'Temp',
},
};
const seriesA = toDataFrame({
name: 'C',
fields: [
{ name: 'Column', type: FieldType.string, values: ['C1', null, 'C2'] },
{ name: 'Row', type: FieldType.string, values: ['R1', 'R2', 'R1'] },
{ name: 'Temp', type: FieldType.number, values: [1, 4, 5], config: { units: 'celsius' } },
],
});
await expect(transformDataFrame([cfg], [seriesA])).toEmitValuesWith((received) => {
const processed = received[0];
expect(processed[0].fields).toMatchInlineSnapshot(`
[
{
"config": {},
"name": "Row\\Column",
"type": "string",
"values": [
"R1",
"R2",
],
},
{
"config": {
"units": "celsius",
},
"name": "C1",
"type": "number",
"values": [
1,
"",
],
},
{
"config": {
"units": "celsius",
},
"name": null,
"type": "number",
"values": [
"",
4,
],
},
{
"config": {
"units": "celsius",
},
"name": "C2",
"type": "number",
"values": [
5,
"",
],
},
]
`);
});
});
it('generates Matrix with multiple fields and value type', async () => {
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
id: DataTransformerID.groupingToMatrix,

View File

@ -127,7 +127,7 @@ export const groupingToMatrixTransformer: DataTransformerInfo<GroupingToMatrixTr
}
fields.push({
name: columnName.toString(),
name: columnName?.toString() ?? null,
values: values,
config: valueField.config,
type: valueField.type,