-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
13 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
96 changes: 96 additions & 0 deletions
96
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,96 @@ | ||
/* | ||
* 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$$$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, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).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); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
/* | ||
* 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'; | ||
|
||
const SEPARATOR = '$$$'; | ||
|
||
function parseSerializedInterval(interval: string | number) { | ||
if (typeof interval === 'number') { | ||
return interval; | ||
} | ||
if (interval === 'auto') { | ||
return 'auto'; | ||
} | ||
return Number(interval.split(SEPARATOR)[1]); | ||
} | ||
|
||
export function buildSerializedAutoInterval(usedInterval: number) { | ||
return `auto${SEPARATOR}${usedInterval}`; | ||
} | ||
|
||
export function isSerializedAutoInterval(interval: string | number) { | ||
return typeof interval === 'string' && interval.startsWith('auto'); | ||
} | ||
|
||
/** | ||
* 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.interval) { | ||
return undefined; | ||
} | ||
return parseSerializedInterval(params.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
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/lens/public/xy_visualization/__snapshots__/expression.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.