Skip to content

Commit

Permalink
[lens] significant terms convert to lens (#159580)
Browse files Browse the repository at this point in the history
Part of #154307

Update convert to lens functionality to support significant terms
aggregation

<img width="500" alt="Screen Shot 2023-06-13 at 8 58 09 AM"
src="https://github.com/elastic/kibana/assets/373691/949199ee-24e2-45d0-84b1-512698abecb4">

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2023
1 parent 24e449e commit 57a1775
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import { getFieldNameFromField, getLabel, isSchemaConfig } from '../utils';

export type BucketAggs =
| BUCKET_TYPES.TERMS
| BUCKET_TYPES.SIGNIFICANT_TERMS
| BUCKET_TYPES.DATE_HISTOGRAM
| BUCKET_TYPES.FILTERS
| BUCKET_TYPES.RANGE
| BUCKET_TYPES.HISTOGRAM;

const SUPPORTED_BUCKETS: string[] = [
BUCKET_TYPES.TERMS,
BUCKET_TYPES.SIGNIFICANT_TERMS,
BUCKET_TYPES.DATE_HISTOGRAM,
BUCKET_TYPES.FILTERS,
BUCKET_TYPES.RANGE,
Expand Down Expand Up @@ -64,6 +66,7 @@ export const getBucketColumns = (
case BUCKET_TYPES.HISTOGRAM:
return convertToRangeColumn(agg.aggId ?? '', agg.aggParams, label, dataView, isSplit);
case BUCKET_TYPES.TERMS:
case BUCKET_TYPES.SIGNIFICANT_TERMS:
const fieldName = getFieldNameFromField(agg.aggParams.field);
if (!fieldName) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,40 @@ describe('convertToDateHistogramColumn', () => {
mockConvertMetricToColumns.mockReturnValue(metricColumns);
},
],
[
'significant terms column',
[
aggId,
{
agg: {
aggType: BUCKET_TYPES.SIGNIFICANT_TERMS,
aggParams: {
field: stubLogstashDataView.fields[0].name,
size: 5,
},
} as SchemaConfig<BUCKET_TYPES.SIGNIFICANT_TERMS>,
dataView: stubLogstashDataView,
aggs,
metricColumns,
visType,
},
'',
false,
],
{
operationType: 'terms',
sourceField: stubLogstashDataView.fields[0].name,
isBucketed: true,
params: {
size: 5,
include: [],
exclude: [],
orderBy: { type: 'significant' },
orderDirection: 'desc',
},
},
() => {},
],
])('should return %s', (_, input, expected, actions) => {
actions();
if (expected === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,34 @@ export const convertToTermsParams = ({
aggs,
metricColumns,
visType,
}: CommonBucketConverterArgs<BUCKET_TYPES.TERMS>): TermsParams | null => {
}: CommonBucketConverterArgs<
BUCKET_TYPES.TERMS | BUCKET_TYPES.SIGNIFICANT_TERMS
>): TermsParams | null => {
if (!agg.aggParams) {
return null;
}

const size = agg.aggParams.size ?? 10;
const exclude = agg.aggParams.exclude ? filterOutEmptyValues(agg.aggParams.exclude) : [];
const include = agg.aggParams.include ? filterOutEmptyValues(agg.aggParams.include) : [];

if (agg.aggType === BUCKET_TYPES.SIGNIFICANT_TERMS) {
return {
size: agg.aggParams.size ?? 10,
orderDirection: 'desc',
include,
exclude,
orderBy: { type: 'significant' },
};
}

const orderByWithAgg = getOrderByWithAgg({ agg, dataView, aggs, metricColumns, visType });
if (orderByWithAgg === null) {
return null;
}

const exclude = agg.aggParams.exclude ? filterOutEmptyValues(agg.aggParams.exclude) : [];
const include = agg.aggParams.include ? filterOutEmptyValues(agg.aggParams.include) : [];
return {
size: agg.aggParams.size ?? 10,
size,
include,
exclude,
includeIsRegex: Boolean(include.length && agg.aggParams.includeIsRegex),
Expand All @@ -117,7 +131,13 @@ export const convertToTermsParams = ({

export const convertToTermsColumn = (
aggId: string,
{ agg, dataView, aggs, metricColumns, visType }: CommonBucketConverterArgs<BUCKET_TYPES.TERMS>,
{
agg,
dataView,
aggs,
metricColumns,
visType,
}: CommonBucketConverterArgs<BUCKET_TYPES.TERMS | BUCKET_TYPES.SIGNIFICANT_TERMS>,
label: string,
isSplit: boolean
): TermsColumn | null => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface TermsParams extends FormatParams {
orderBy:
| { type: 'alphabetical'; fallback?: boolean }
| { type: 'rare'; maxDocCount: number }
| { type: 'significant' }
| { type: 'column'; columnId: string }
| { type: 'custom' };
orderAgg?: Column;
Expand Down

0 comments on commit 57a1775

Please sign in to comment.