Transformations: Fix bug with calculate field when using reduce and the all values calculation (#75684)

* fix reduce all fields

* Add test for issue
This commit is contained in:
Oscar Kilhed 2023-09-29 04:19:10 +02:00 committed by GitHub
parent 27aa1c466a
commit 523cb97aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -254,7 +254,7 @@ export const fieldReducers = new Registry<FieldReducerInfo>(() => [
name: 'All values',
description: 'Returns an array with all values',
standard: false,
reduce: (field: Field) => ({ allValues: field.values }),
reduce: (field: Field) => ({ allValues: [...field.values] }),
},
{
id: ReducerID.uniqueValues,

View File

@ -222,6 +222,33 @@ describe('calculateField transformer w/ timeseries', () => {
});
});
it('reduces all field', async () => {
const cfg = {
id: DataTransformerID.calculateField,
options: {
mode: CalculateFieldMode.ReduceRow,
reduce: { include: ['B', 'C'], reducer: ReducerID.allValues },
replaceFields: true,
},
};
await expect(transformDataFrame([cfg], [seriesBC])).toEmitValuesWith((received) => {
const data = received[0];
const filtered = data[0];
const rows = new DataFrameView(filtered).toArray();
expect(rows).toEqual([
{
'All values': [2, 3],
TheTime: 1000,
},
{
'All values': [200, 300],
TheTime: 2000,
},
]);
});
});
it('can add index field', async () => {
const cfg = {
id: DataTransformerID.calculateField,