-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ES|QL] Improve suggestions based on previous function arguments and date suggestions for bucket
#190828
Conversation
…ignatures-suggestions # Conflicts: # packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts
…ignatures-suggestions
@@ -125,7 +126,10 @@ export default function DegradedDocs({ lastReloadTime }: { lastReloadTime: numbe | |||
<EuiButtonIcon | |||
display="base" | |||
iconType="discoverApp" | |||
aria-label="Discover" | |||
aria-label={i18n.translate( |
There was a problem hiding this comment.
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 🤔
/ci |
bucket
} | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(`Failed query\n-------------\n${query}`); |
There was a problem hiding this comment.
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.
/ci |
@elasticmachine merge upstream |
/ci |
@elasticmachine merge upstream |
Pinging @elastic/kibana-esql (Team:ESQL) |
There was a problem hiding this 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', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here a0a67d8
(#190828)
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing explanation
There was a problem hiding this comment.
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}` |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here a0a67d8
(#190828)
@elasticmachine merge upstream |
f8efe7a
to
abcaab4
Compare
@drewdaemon As discussed in office hours, I've added the 'Add date histogram' snippet to this PR which pre-populates with |
There was a problem hiding this 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', |
There was a problem hiding this comment.
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
sortText: '1A', | |
sortText: '1A', | |
command: TRIGGER_SUGGESTIONS_COMMAND, |
There was a problem hiding this comment.
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)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
💚 Build Succeeded
Metrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @qn895 |
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 <>
withBUCKET(<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:
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:
For maintainers