-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Pass used histogram interval to chart (#91370)
- Loading branch information
Showing
11 changed files
with
308 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/plugins/data/common/search/aggs/utils/get_number_histogram_interval.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getNumberHistogramIntervalByDatatableColumn } from '.'; | ||
import { BUCKET_TYPES } from '../buckets'; | ||
|
||
describe('getNumberHistogramIntervalByDatatableColumn', () => { | ||
it('returns nothing on column from other data source', () => { | ||
expect( | ||
getNumberHistogramIntervalByDatatableColumn({ | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
type: 'date', | ||
source: 'essql', | ||
}, | ||
}) | ||
).toEqual(undefined); | ||
}); | ||
|
||
it('returns nothing on non histogram column', () => { | ||
expect( | ||
getNumberHistogramIntervalByDatatableColumn({ | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
type: 'date', | ||
source: 'esaggs', | ||
sourceParams: { | ||
type: BUCKET_TYPES.TERMS, | ||
}, | ||
}, | ||
}) | ||
).toEqual(undefined); | ||
}); | ||
|
||
it('returns interval on resolved auto interval', () => { | ||
expect( | ||
getNumberHistogramIntervalByDatatableColumn({ | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
type: 'date', | ||
source: 'esaggs', | ||
sourceParams: { | ||
type: BUCKET_TYPES.HISTOGRAM, | ||
params: { | ||
interval: 'auto', | ||
used_interval: 20, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toEqual(20); | ||
}); | ||
|
||
it('returns interval on fixed interval', () => { | ||
expect( | ||
getNumberHistogramIntervalByDatatableColumn({ | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
type: 'date', | ||
source: 'esaggs', | ||
sourceParams: { | ||
type: BUCKET_TYPES.HISTOGRAM, | ||
params: { | ||
interval: 7, | ||
used_interval: 7, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toEqual(7); | ||
}); | ||
|
||
it('returns undefined if information is not available', () => { | ||
expect( | ||
getNumberHistogramIntervalByDatatableColumn({ | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
type: 'date', | ||
source: 'esaggs', | ||
sourceParams: { | ||
type: BUCKET_TYPES.HISTOGRAM, | ||
params: {}, | ||
}, | ||
}, | ||
}) | ||
).toEqual(undefined); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/plugins/data/common/search/aggs/utils/get_number_histogram_interval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { DatatableColumn } from 'src/plugins/expressions/common'; | ||
import type { AggParamsHistogram } from '../buckets'; | ||
import { BUCKET_TYPES } from '../buckets/bucket_agg_types'; | ||
|
||
/** | ||
* Helper function returning the used interval for data table column created by the histogramm agg type. | ||
* "auto" will get expanded to the actually used interval. | ||
* If the column is not a column created by a histogram aggregation of the esaggs data source, | ||
* this function will return undefined. | ||
*/ | ||
export const getNumberHistogramIntervalByDatatableColumn = (column: DatatableColumn) => { | ||
if (column.meta.source !== 'esaggs') return; | ||
if (column.meta.sourceParams?.type !== BUCKET_TYPES.HISTOGRAM) return; | ||
const params = (column.meta.sourceParams.params as unknown) as AggParamsHistogram; | ||
|
||
if (!params.used_interval || typeof params.used_interval === 'string') { | ||
return undefined; | ||
} | ||
return params.used_interval; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.