mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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);
|
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', () => {
|
it('consistently check allIsNull/allIsZero', () => {
|
||||||
const empty = createField('x');
|
const empty = createField('x');
|
||||||
const allNull = createField('x', [null, null, null, null]);
|
const allNull = createField('x', [null, null, null, null]);
|
||||||
|
@ -25,6 +25,7 @@ export enum ReducerID {
|
|||||||
allIsZero = 'allIsZero',
|
allIsZero = 'allIsZero',
|
||||||
allIsNull = 'allIsNull',
|
allIsNull = 'allIsNull',
|
||||||
allValues = 'allValues',
|
allValues = 'allValues',
|
||||||
|
uniqueValues = 'uniqueValues',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal function
|
// Internal function
|
||||||
@ -237,6 +238,15 @@ export const fieldReducers = new Registry<FieldReducerInfo>(() => [
|
|||||||
standard: false,
|
standard: false,
|
||||||
reduce: (field: Field) => ({ allValues: field.values.toArray() }),
|
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 {
|
export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||||
|
Loading…
Reference in New Issue
Block a user