mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 16:57:14 -06:00
Transformations: Add an All Unique Values Reducer (#48653)
This commit is contained in:
parent
dac8abfc2c
commit
570ff074f6
@ -97,6 +97,15 @@ describe('Stats Calculators', () => {
|
||||
expect(stats.delta).toEqual(300);
|
||||
});
|
||||
|
||||
it('should calculate unique values', () => {
|
||||
const stats = reduceField({
|
||||
field: createField('x', [1, 2, 2, 3, 1]),
|
||||
reducers: [ReducerID.uniqueValues],
|
||||
});
|
||||
|
||||
expect(stats.uniqueValues).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('consistently check allIsNull/allIsZero', () => {
|
||||
const empty = createField('x');
|
||||
const allNull = createField('x', [null, null, null, null]);
|
||||
|
@ -25,6 +25,7 @@ export enum ReducerID {
|
||||
allIsZero = 'allIsZero',
|
||||
allIsNull = 'allIsNull',
|
||||
allValues = 'allValues',
|
||||
uniqueValues = 'uniqueValues',
|
||||
}
|
||||
|
||||
// Internal function
|
||||
@ -237,6 +238,15 @@ export const fieldReducers = new Registry<FieldReducerInfo>(() => [
|
||||
standard: false,
|
||||
reduce: (field: Field) => ({ allValues: field.values.toArray() }),
|
||||
},
|
||||
{
|
||||
id: ReducerID.uniqueValues,
|
||||
name: 'All unique values',
|
||||
description: 'Returns an array with all unique values',
|
||||
standard: false,
|
||||
reduce: (field: Field) => ({
|
||||
uniqueValues: [...new Set(field.values.toArray())],
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
|
Loading…
Reference in New Issue
Block a user