Skip to content

Commit

Permalink
[ES|QL] Improve suggestions based on previous function arguments and …
Browse files Browse the repository at this point in the history
…date suggestions for `bucket` (#190828)

This PR improves logic for autocomplete suggestions to suggest new
function args based on previous values. For example:


https://github.com/user-attachments/assets/b597cd52-1ca9-479c-b7f0-67ed464b5659


It also adds a new snippet 'Add date histogram' for `stats ... by <>`




https://github.com/user-attachments/assets/994cbc5a-1760-446e-80e5-d9faeae2ba73



As part of this PR, test cases for eval functions were also updated to
cover all possible arguments while avoiding running the same test cases
repetitively. For example:

        'st_contains( / )',
        'st_contains(cartesianPointField,  / )',
        'st_contains(cartesianPointField, cartesianPointField,  / )',
        'st_contains(cartesianPointField, cartesianShapeField,  / )',
        'st_contains(cartesianShapeField,  / )',
        'st_contains(cartesianShapeField, cartesianPointField,  / )',
        'st_contains(cartesianShapeField, cartesianShapeField,  / )',
        'st_contains(geoPointField,  / )',
        'st_contains(geoPointField, geoPointField,  / )',
        'st_contains(geoPointField, geoShapeField,  / )',
        'st_contains(geoShapeField,  / )',
        'st_contains(geoShapeField, geoPointField,  / )',
        'st_contains(geoShapeField, geoShapeField,  / )'

        'mv_slice( / )',
        'mv_slice(booleanField,  / )',
        'mv_slice(booleanField, integerField,  / )',
        'mv_slice(booleanField, integerField, integerField,  / )',
        'mv_slice(cartesianPointField,  / )',
        'mv_slice(cartesianPointField, integerField,  / )',
'mv_slice(cartesianPointField, integerField, integerField, / )',
        'mv_slice(cartesianShapeField,  / )',
        'mv_slice(cartesianShapeField, integerField,  / )',
'mv_slice(cartesianShapeField, integerField, integerField, / )',
        'mv_slice(dateField,  / )',
        'mv_slice(dateField, integerField,  / )',
        'mv_slice(dateField, integerField, integerField,  / )',
        'mv_slice(doubleField,  / )',
        'mv_slice(doubleField, integerField,  / )',
        'mv_slice(doubleField, integerField, integerField,  / )',
        'mv_slice(geoPointField,  / )',
        'mv_slice(geoPointField, integerField,  / )',
        'mv_slice(geoPointField, integerField, integerField,  / )',
        'mv_slice(geoShapeField,  / )',
        'mv_slice(geoShapeField, integerField,  / )',
        'mv_slice(geoShapeField, integerField, integerField,  / )',
        'mv_slice(integerField,  / )',
        'mv_slice(integerField, integerField,  / )',
        'mv_slice(integerField, integerField, integerField,  / )',
        'mv_slice(ipField,  / )',
        'mv_slice(ipField, integerField,  / )',
        'mv_slice(ipField, integerField, integerField,  / )',
        'mv_slice(keywordField,  / )',
        'mv_slice(keywordField, integerField,  / )',
        'mv_slice(keywordField, integerField, integerField,  / )',
        'mv_slice(longField,  / )',
        'mv_slice(longField, integerField,  / )',
        'mv_slice(longField, integerField, integerField,  / )',
        'mv_slice(textField,  / )',
        'mv_slice(textField, integerField,  / )',
        'mv_slice(textField, integerField, integerField,  / )',
        'mv_slice(versionField,  / )',
        'mv_slice(versionField, integerField,  / )',
        'mv_slice(versionField, integerField, integerField,  / )'


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
qn895 and elasticmachine authored Aug 30, 2024
1 parent cdb1eb8 commit 70a33f4
Show file tree
Hide file tree
Showing 9 changed files with 822 additions and 580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

import { ESQL_COMMON_NUMERIC_TYPES, ESQL_NUMBER_TYPES } from '../../shared/esql_types';
import { ADD_DATE_HISTOGRAM_SNIPPET } from '../factories';
import { roundParameterTypes } from './constants';
import { setup, getFunctionSignaturesByReturnType, getFieldNamesByType } from './helpers';

const allAggFunctions = getFunctionSignaturesByReturnType('stats', 'any', {
Expand Down Expand Up @@ -82,7 +84,6 @@ describe('autocomplete.suggest', () => {
scalar: true,
}).map((s) => ({ ...s, text: `${s.text},` })),
]);
const roundParameterTypes = ['double', 'integer', 'long', 'unsigned_long'] as const;
await assertSuggestions('from a | stats round(/', [
...getFunctionSignaturesByReturnType('stats', roundParameterTypes, {
agg: true,
Expand Down Expand Up @@ -213,6 +214,7 @@ describe('autocomplete.suggest', () => {
const { assertSuggestions } = await setup();
const expected = [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
Expand All @@ -235,6 +237,7 @@ describe('autocomplete.suggest', () => {
const fields = getFieldNamesByType('any').map((field) => `${field} `);
await assertSuggestions('from a | stats a=c by d, /', [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...fields,
...allEvaFunctions,
...allGroupingFunctions,
Expand All @@ -246,6 +249,7 @@ describe('autocomplete.suggest', () => {
]);
await assertSuggestions('from a | stats avg(b) by c, /', [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...fields,
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...allGroupingFunctions,
Expand All @@ -267,11 +271,13 @@ describe('autocomplete.suggest', () => {
...allGroupingFunctions,
]);
await assertSuggestions('from a | stats avg(b) by var0 = /', [
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
]);
await assertSuggestions('from a | stats avg(b) by c, var0 = /', [
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
Expand Down
Loading

0 comments on commit 70a33f4

Please sign in to comment.