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

[Lens] improve percentile agg optimizations #145303

Merged
Merged
17 changes: 1 addition & 16 deletions x-pack/plugins/lens/public/datasources/form_based/dedupe_aggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,9 @@ import {
ExpressionAstFunctionBuilder,
} from '@kbn/expressions-plugin/common';
import { GenericOperationDefinition } from './operations';
import { groupByKey } from './operations/definitions/get_group_by_key';
import { extractAggId, OriginalColumn } from './to_expression';

function groupByKey<T>(items: T[], getKey: (item: T) => string | undefined): Record<string, T[]> {
const groups: Record<string, T[]> = {};

items.forEach((item) => {
const key = getKey(item);
if (key) {
if (!(key in groups)) {
groups[key] = [];
}
groups[key].push(item);
}
});

return groups;
}

/**
* Consolidates duplicate agg expression builders to increase performance
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ import {
} from '@kbn/expressions-plugin/common';
import { Primitive } from 'utility-types';

export function groupByKey<T>(
items: T[],
getKey: (item: T) => string | undefined
): Record<string, T[]> {
const groups: Record<string, T[]> = {};

items.forEach((item) => {
const key = getKey(item);
if (key) {
if (!(key in groups)) {
groups[key] = [];
}
groups[key].push(item);
}
});

return groups;
}

/**
* Computes a group-by key for an agg expression builder based on distinctive expression function arguments
*/
Expand Down
Loading