-
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.
[ES|QL] Support counter fields (#186292)
- Closes #186160 ## Summary This PR adds a new util to help with converting ES|QL column into data view field representation https://github.com/elastic/kibana/blob/9d63332c74523b00f2b9056352a5b3a86eaf2b75/packages/kbn-data-view-utils/src/utils/convert_to_data_view_field.ts#L13 This allows to handle counter fields in a more predicable way despite of the different format of ES|QL column data. #186154 (comment) <img width="1988" alt="Screenshot 2024-07-03 at 13 48 20" src="https://github.com/elastic/kibana/assets/1415710/14ce9cd8-8a02-4f3c-8845-c19c30079a75"> --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Stratoula Kalafateli <[email protected]> Co-authored-by: Matthias Wilhelm <[email protected]>
- Loading branch information
1 parent
2e8ca07
commit 692b656
Showing
8 changed files
with
113 additions
and
15 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
60 changes: 60 additions & 0 deletions
60
packages/kbn-data-view-utils/src/utils/convert_to_data_view_field_spec.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,60 @@ | ||
/* | ||
* 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 { DatatableColumnType } from '@kbn/expressions-plugin/common'; | ||
import { convertDatatableColumnToDataViewFieldSpec } from './convert_to_data_view_field_spec'; | ||
|
||
describe('convertDatatableColumnToDataViewFieldSpec', () => { | ||
it('should return a DataViewField object for a counter column', () => { | ||
const column = { | ||
id: 'bytes_counter', | ||
name: 'bytes_counter', | ||
meta: { | ||
esType: 'counter_long', | ||
type: 'number' as DatatableColumnType, | ||
}, | ||
isNull: false, | ||
}; | ||
const result = convertDatatableColumnToDataViewFieldSpec(column); | ||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
name: 'bytes_counter', | ||
type: 'number', | ||
esTypes: ['long'], | ||
searchable: true, | ||
aggregatable: false, | ||
isNull: false, | ||
timeSeriesMetric: 'counter', | ||
}) | ||
); | ||
}); | ||
|
||
it('should return a DataViewField object with timeSeriesMetric undefined if esType does not start with counter_', () => { | ||
const column = { | ||
id: 'test', | ||
name: 'test', | ||
meta: { | ||
esType: 'keyword', | ||
type: 'string' as DatatableColumnType, | ||
}, | ||
isNull: false, | ||
}; | ||
const result = convertDatatableColumnToDataViewFieldSpec(column); | ||
expect(result.timeSeriesMetric).toBeUndefined(); | ||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
name: 'test', | ||
type: 'string', | ||
esTypes: ['keyword'], | ||
searchable: true, | ||
aggregatable: false, | ||
isNull: false, | ||
}) | ||
); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/kbn-data-view-utils/src/utils/convert_to_data_view_field_spec.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,37 @@ | ||
/* | ||
* 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 type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
import type { MappingTimeSeriesMetricType } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import type { FieldSpec } from '@kbn/data-views-plugin/common'; | ||
|
||
/** | ||
* Convert a datatable column to a DataViewFieldSpec | ||
*/ | ||
export function convertDatatableColumnToDataViewFieldSpec(column: DatatableColumn): FieldSpec { | ||
let esType = column.meta?.esType; | ||
let timeSeriesMetric: MappingTimeSeriesMetricType | undefined; | ||
|
||
// 'counter_integer', 'counter_long', 'counter_double'... | ||
if (esType?.startsWith('counter_')) { | ||
esType = esType?.replace('counter_', ''); | ||
timeSeriesMetric = 'counter'; | ||
} | ||
|
||
// `DataViewField` class is defined in "data-views" plugin, so we can't create an instance of it from a package. | ||
// We will return a data view field spec here instead then. | ||
return { | ||
name: column.name, | ||
type: column.meta?.type ?? 'unknown', | ||
esTypes: esType ? [esType] : undefined, | ||
searchable: true, | ||
aggregatable: false, | ||
isNull: Boolean(column?.isNull), | ||
...(timeSeriesMetric ? { timeSeriesMetric } : {}), | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -14,5 +14,9 @@ | |
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/data-views-plugin", | ||
"@kbn/expressions-plugin", | ||
] | ||
} |
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
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