Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Improve suggestions based on previous function arguments and date suggestions for bucket #190828

Merged
merged 27 commits into from
Aug 30, 2024

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Aug 20, 2024

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

Screen.Recording.2024-08-20.at.14.57.57.mov

It also adds a new snippet 'Add date histogram' for stats ... by <> with BUCKET(<cursor>, 10, ?t_start, ?t_end)'

Screen.Recording.2024-08-30.at.14.11.10.mov

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.

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—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—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

For maintainers

@@ -125,7 +126,10 @@ export default function DegradedDocs({ lastReloadTime }: { lastReloadTime: numbe
<EuiButtonIcon
display="base"
iconType="discoverApp"
aria-label="Discover"
aria-label={i18n.translate(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting is causing this change automatically 🤔

@qn895
Copy link
Member Author

qn895 commented Aug 20, 2024

/ci

@qn895 qn895 changed the title [ES|QL] Improve suggestions based on previous function args [ES|QL] Improve suggestions based on previous function arguments and date suggestions for bucket Aug 20, 2024
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Failed query\n-------------\n${query}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this one liner so if a test fails, it will print out which case specifically failed. I made this because it was getting hard to find the needle in the haystack to figure out which case inside the test suite failed.

@qn895
Copy link
Member Author

qn895 commented Aug 20, 2024

/ci

@qn895
Copy link
Member Author

qn895 commented Aug 22, 2024

@elasticmachine merge upstream

@qn895
Copy link
Member Author

qn895 commented Aug 23, 2024

/ci

@qn895
Copy link
Member Author

qn895 commented Aug 27, 2024

@elasticmachine merge upstream

@qn895 qn895 marked this pull request as ready for review August 27, 2024 15:47
@qn895 qn895 requested review from a team as code owners August 27, 2024 15:47
@qn895 qn895 self-assigned this Aug 27, 2024
@qn895 qn895 added the Feature:ES|QL ES|QL related features in Kibana label Aug 27, 2024
@qn895 qn895 added Team:ESQL ES|QL related features in Kibana v8.16.0 labels Aug 27, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I did notice that after I select my first date parameter with the date picker, I don't get suggestions for the second date parameter:

Screen.Recording.2024-08-28.at.11.01.13.AM.mov

@@ -429,459 +409,7 @@ describe('autocomplete', () => {
}
});

describe('eval', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a clean copy, or did we add cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the tests actually to test all possible arguments

@@ -93,6 +102,59 @@ export function getSupportedTypesForBinaryOperators(
: [previousType];
}

export function getValidFunctionSignaturesForPreviousArgs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. This will come in handy with #180518 as well

Comment on lines +75 to +78
if (a === 'time_literal' || a === 'time_duration') return b === 'timeInterval';
if (b === 'time_literal' || b === 'time_duration') return a === 'timeInterval';
if (a === 'time_literal') return b === 'time_duration';
if (b === 'time_literal') return a === 'time_duration';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we pretend that a new developer is looking at this and add a comment here about the date type weirdness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here a0a67d8 (#190828)

}

/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing explanation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here a0a67d8 (#190828)

);
const compatibleTypesToSuggestForArg = uniqBy(
relevantFuncSignatures.map((f) => f.params[argIndex]).filter((d) => d),
(o) => `${o.type}-${o.constantOnly}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever

@@ -57,6 +59,13 @@ export function getParamAtPosition(
return params.length > position ? params[position] : minParams ? params[params.length - 1] : null;
}

export function strictlyGetParamAtPosition(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a function comment about what "strictly" means in this context would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here a0a67d8 (#190828)

@@ -446,7 +448,7 @@ function areCurrentArgsValid(
return true;
}

function extractFinalTypeFromArg(
export function extractFinalTypeFromArg(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't name this function. But, does "Final" mean anything to you? I'm wondering if this should just be called extractTypeFromASTArg or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here a0a67d8 (#190828)

};

const enrichedArgs = node.args.map((nodeArg) => {
let esType = extractFinalTypeFromArg(nodeArg, references);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any reason not to call this dataType?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here a0a67d8 (#190828)

@stratoula stratoula removed the request for review from a team August 29, 2024 05:46
@qn895
Copy link
Member Author

qn895 commented Aug 29, 2024

@elasticmachine merge upstream

@qn895 qn895 force-pushed the esql-improve-func-signatures-suggestions branch from f8efe7a to abcaab4 Compare August 30, 2024 17:07
@qn895
Copy link
Member Author

qn895 commented Aug 30, 2024

@drewdaemon As discussed in office hours, I've added the 'Add date histogram' snippet to this PR which pre-populates with BUCKET($0, 20, ?start, ?end). Also made some modification on how comma/advance suggestion is added so no longer add comma if it detects there's already a comma right after the cursor.

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! This is a major improvement to BUCKET 👏

Just make sure we get those parameter names changed to t_start and t_end before merging.

defaultMessage: 'Add date histogram using bucket()',
}
),
sortText: '1A',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should open the suggestions menu when the user accepts the date histogram snippet

Suggested change
sortText: '1A',
sortText: '1A',
command: TRIGGER_SUGGESTIONS_COMMAND,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here ca2d8e7 (#190828)

@@ -30,6 +30,7 @@ const allFunctions = statsAggregationFunctionDefinitions
.concat(groupingFunctionDefinitions);

export const TIME_SYSTEM_PARAMS = ['?t_start', '?t_end'];
export const ADD_DATE_HISTOGRAM_SNIPPET = 'BUCKET($0, 20, ?start, ?end)';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const ADD_DATE_HISTOGRAM_SNIPPET = 'BUCKET($0, 20, ?start, ?end)';
export const ADD_DATE_HISTOGRAM_SNIPPET = 'BUCKET($0, 20, ?t_start, ?t_end)';

Also, I have no idea if 20 is the right number here. Not necessarily something we have to block this PR on, but could you make sure we discuss this as a team?

@qn895 qn895 enabled auto-merge (squash) August 30, 2024 19:02
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.3MB 3.3MB +1020.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/esql-validation-autocomplete 1 2 +1

Total ESLint disabled count

id before after diff
@kbn/esql-validation-autocomplete 1 2 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @qn895

@qn895 qn895 merged commit 70a33f4 into elastic:main Aug 30, 2024
20 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:enhancement Team:ESQL ES|QL related features in Kibana v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants