Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformations: Add an All Unique Values Reducer #48653

Merged
merged 7 commits into from May 4, 2022
Merged
10 changes: 10 additions & 0 deletions packages/grafana-data/src/transformations/fieldReducer.ts
Expand Up @@ -25,6 +25,7 @@ export enum ReducerID {
allIsZero = 'allIsZero',
allIsNull = 'allIsNull',
allValues = 'allValues',
allUniqueValues = 'allUniqueValues',
josiahg marked this conversation as resolved.
Show resolved Hide resolved
}

// Internal function
Expand Down Expand Up @@ -237,6 +238,15 @@ export const fieldReducers = new Registry<FieldReducerInfo>(() => [
standard: false,
reduce: (field: Field) => ({ allValues: field.values.toArray() }),
},
{
id: ReducerID.allUniqueValues,
name: 'All unique values',
description: 'Returns an array with all unique values',
standard: false,
reduce: (field: Field) => ({
allUniqueValues: field.values.toArray().filter((n, i) => field.values.toArray().indexOf(n) === i),
josiahg marked this conversation as resolved.
Show resolved Hide resolved
}),
},
]);

export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
Expand Down