-
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.
[ES|QL][UnifiedFieldList] Support field stats for ES|QL query (#178433)
- Closes #174984 ## Summary This PR adds field stats for ES|QL mode in Discover. It will show "Top values" for `keyword`, `ip`, `boolean`, `number`, `version` fields and "Examples" for `text` and geo fields. Also this PR extends text based column's meta with `esType` to make it easier to differentiate between `keyword` and `text` columns when kibana type for both is `string`. This change also has a UI improvement: `k` token will be shown next to keyword fields in data grid column header and in doc viewer instead of `t` token. And it will be possible to filter by Keyword/Text types in the fields sidebar for ES|QL mode. <img width="400" alt="Screenshot 2024-03-13 at 18 29 47" src="https://github.com/elastic/kibana/assets/1415710/d88e85c3-329f-44fc-af54-3493dd9896d0"> <img width="400" alt="Screenshot 2024-03-13 at 18 30 01" src="https://github.com/elastic/kibana/assets/1415710/b0808860-28db-472b-a0e3-37fc857bb40c"> <img width="400" alt="Screenshot 2024-03-13 at 18 30 19" src="https://github.com/elastic/kibana/assets/1415710/b571199c-5956-472c-a0f7-c1b3d9bfe473"> <img width="400" alt="Screenshot 2024-03-13 at 18 30 13" src="https://github.com/elastic/kibana/assets/1415710/a8e46b97-da38-4cbb-8980-fff214e09818"> <img width="400" alt="Screenshot 2024-03-13 at 18 30 06" src="https://github.com/elastic/kibana/assets/1415710/8d1495ea-36d5-4203-9e86-90e7ea22cfe9"> <img width="400" alt="Screenshot 2024-03-13 at 18 31 50" src="https://github.com/elastic/kibana/assets/1415710/b0660c57-aea8-4570-a72b-22df4c15dcc8"> <img width="400" alt="Screenshot 2024-03-13 at 18 30 50" src="https://github.com/elastic/kibana/assets/1415710/9f81f7a8-7cba-44db-bbef-f1f1cb8e1093"> 25x flaky test https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5470 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
3069efd
commit e2da5af
Showing
56 changed files
with
1,485 additions
and
268 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2581,4 +2581,4 @@ | |
} | ||
] | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
packages/kbn-esql-utils/src/utils/get_esql_with_safe_limit.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,31 @@ | ||
/* | ||
* 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 { getESQLWithSafeLimit } from './get_esql_with_safe_limit'; | ||
|
||
const LIMIT = 10000; | ||
|
||
describe('getESQLWithSafeLimit()', () => { | ||
it('should not add the limit', () => { | ||
expect(getESQLWithSafeLimit('show info', LIMIT)).toBe('show info'); | ||
expect(getESQLWithSafeLimit('row t = 5', LIMIT)).toBe('row t = 5'); | ||
}); | ||
|
||
it('should add the limit', () => { | ||
expect(getESQLWithSafeLimit(' from logs', LIMIT)).toBe('from logs | LIMIT 10000'); | ||
expect(getESQLWithSafeLimit('FROM logs* | LIMIT 5', LIMIT)).toBe( | ||
'FROM logs* | LIMIT 10000| LIMIT 5' | ||
); | ||
expect(getESQLWithSafeLimit('FROM logs* | SORT @timestamp | LIMIT 5', LIMIT)).toBe( | ||
'FROM logs* |SORT @timestamp | LIMIT 10000| LIMIT 5' | ||
); | ||
expect(getESQLWithSafeLimit('from logs* | STATS MIN(a) BY b', LIMIT)).toBe( | ||
'from logs* | LIMIT 10000| STATS MIN(a) BY b' | ||
); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/kbn-esql-utils/src/utils/get_esql_with_safe_limit.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,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export function getESQLWithSafeLimit(esql: string, limit: number): string { | ||
if (!esql.trim().toLowerCase().startsWith('from')) { | ||
return esql; | ||
} | ||
const parts = esql.split('|'); | ||
|
||
if (!parts.length) { | ||
return esql; | ||
} | ||
|
||
const fromCommandIndex = 0; | ||
const sortCommandIndex = 1; | ||
const index = | ||
parts.length > 1 && parts[1].trim().toLowerCase().startsWith('sort') | ||
? sortCommandIndex | ||
: fromCommandIndex; | ||
|
||
return parts | ||
.map((part, i) => { | ||
if (i === index) { | ||
return `${part.trim()} | LIMIT ${limit}`; | ||
} | ||
return part; | ||
}) | ||
.join('|'); | ||
} |
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
28 changes: 28 additions & 0 deletions
28
packages/kbn-field-utils/src/utils/get_text_based_column_icon_type.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 type { DatatableColumnMeta } from '@kbn/expressions-plugin/common'; | ||
import { getFieldIconType } from './get_field_icon_type'; | ||
|
||
export function getTextBasedColumnIconType( | ||
columnMeta: | ||
| { | ||
type: DatatableColumnMeta['type']; | ||
esType?: DatatableColumnMeta['esType']; | ||
} | ||
| undefined | ||
| null | ||
): string | null { | ||
return columnMeta && columnMeta.type | ||
? getFieldIconType({ | ||
name: '', | ||
type: columnMeta.type, | ||
esTypes: columnMeta.esType ? [columnMeta.esType] : [], | ||
}) | ||
: null; | ||
} |
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
24 changes: 17 additions & 7 deletions
24
...ages/kbn-unified-data-table/src/components/__snapshots__/data_table_columns.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.