|
|
|
@ -305,4 +305,66 @@ describe('GroupBy transformer', () => { |
|
|
|
|
expect(result[0].fields).toEqual(expected); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should group by and skip fields that do not have values for a group', async () => { |
|
|
|
|
const testSeries1 = toDataFrame({ |
|
|
|
|
name: 'Series1', |
|
|
|
|
fields: [ |
|
|
|
|
{ name: 'Time', type: FieldType.time, values: [1688470200000, 1688471100000, 1688470200000, 1688471100000] }, |
|
|
|
|
{ name: 'Value', type: FieldType.number, values: [1, 2, 3, 4] }, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const testSeries2 = toDataFrame({ |
|
|
|
|
name: 'Series2', |
|
|
|
|
fields: [ |
|
|
|
|
{ name: 'Time', type: FieldType.time, values: [] }, |
|
|
|
|
{ name: 'Value', type: FieldType.number, values: [] }, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const cfg: DataTransformerConfig<GroupByTransformerOptions> = { |
|
|
|
|
id: DataTransformerID.groupBy, |
|
|
|
|
options: { |
|
|
|
|
fields: { |
|
|
|
|
Series1: { |
|
|
|
|
operation: GroupByOperationID.aggregate, |
|
|
|
|
aggregations: [ReducerID.sum], |
|
|
|
|
}, |
|
|
|
|
Series2: { |
|
|
|
|
operation: GroupByOperationID.aggregate, |
|
|
|
|
aggregations: [ReducerID.sum], |
|
|
|
|
}, |
|
|
|
|
Time: { |
|
|
|
|
operation: GroupByOperationID.groupBy, |
|
|
|
|
aggregations: [], |
|
|
|
|
}, |
|
|
|
|
Value: { |
|
|
|
|
operation: GroupByOperationID.aggregate, |
|
|
|
|
aggregations: [ReducerID.sum], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await expect(transformDataFrame([cfg], [testSeries1, testSeries2])).toEmitValuesWith((received) => { |
|
|
|
|
const result = received[0]; |
|
|
|
|
const expected: Field[] = [ |
|
|
|
|
{ |
|
|
|
|
name: 'Time', |
|
|
|
|
type: FieldType.time, |
|
|
|
|
values: [1688470200000, 1688471100000], |
|
|
|
|
config: {}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: 'Value (sum)', |
|
|
|
|
type: FieldType.number, |
|
|
|
|
values: [4, 6], |
|
|
|
|
config: {}, |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
expect(result[0].fields).toEqual(expected); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|