-
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
[KQL] Fix node builder with empty array #155901
Conversation
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
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.
code LGTM, but will be leaving a question in the comments ...
I'm curious about this change. What happens when this is converted to ES? Naively, if previously a clause was generating Seems like this could break some things. |
💚 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 @lukasolson |
The code for converting to ES DSL is here: kibana/packages/kbn-es-query/src/kuery/ast/ast.ts Lines 73 to 75 in 1cbf83f
We treat an |
return nodeTypes.function.buildNodeWithArgumentNodes('is', [ | ||
nodeTypes.literal.buildNode(fieldName), | ||
typeof value === 'string' ? nodeTypes.literal.buildNode(value) : value, | ||
]); | ||
}, | ||
or: (nodes: KueryNode[]): KueryNode => { | ||
return nodes.length > 1 ? nodeTypes.function.buildNode('or', nodes) : nodes[0]; | ||
return nodes.length === 1 ? nodes[0] : nodeTypes.function.buildNode('or', nodes); |
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.
Wouldn't this also work?
return nodes.length === 1 ? nodes[0] : nodeTypes.function.buildNode('or', nodes); | |
return nodeTypes.function.buildNode('or', nodes); |
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.
Spoke to you about this offline, but just adding a note here. Returning the first node is a slight optimization (don't need to build an extra node, and don't have to wrap the ES query in an additional unnecessary bool
clause).
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.
LGTM, thx for taking care of this 🙇. didn't test, but unit tests do, just a tiny question I've been adding
## Summary Fixes elastic#95657. Updates the logic for `nodeBuilder` when passing an empty array to `nodeBuilder.and`/`nodeBuilder.or` to actually return a `KueryNode` instead of `undefined`. ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [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 (cherry picked from commit 654287b)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
# Backport This will backport the following commits from `main` to `8.8`: - [[KQL] Fix node builder with empty array (#155901)](#155901) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Lukas Olson","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-04-27T18:28:12Z","message":"[KQL] Fix node builder with empty array (#155901)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/95657.\r\n\r\nUpdates the logic for `nodeBuilder` when passing an empty array to\r\n`nodeBuilder.and`/`nodeBuilder.or` to actually return a `KueryNode`\r\ninstead of `undefined`.\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"654287b3adc928dd1582998504b7ed043259c3ae","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:KQL","release_note:skip","backport:skip","Team:DataDiscovery","v8.9.0"],"number":155901,"url":"https://github.com/elastic/kibana/pull/155901","mergeCommit":{"message":"[KQL] Fix node builder with empty array (#155901)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/95657.\r\n\r\nUpdates the logic for `nodeBuilder` when passing an empty array to\r\n`nodeBuilder.and`/`nodeBuilder.or` to actually return a `KueryNode`\r\ninstead of `undefined`.\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"654287b3adc928dd1582998504b7ed043259c3ae"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155901","number":155901,"mergeCommit":{"message":"[KQL] Fix node builder with empty array (#155901)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/95657.\r\n\r\nUpdates the logic for `nodeBuilder` when passing an empty array to\r\n`nodeBuilder.and`/`nodeBuilder.or` to actually return a `KueryNode`\r\ninstead of `undefined`.\r\n\r\n### Checklist\r\n\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"654287b3adc928dd1582998504b7ed043259c3ae"}}]}] BACKPORT--> Co-authored-by: Lukas Olson <[email protected]>
Summary
Fixes #95657.
Updates the logic for
nodeBuilder
when passing an empty array tonodeBuilder.and
/nodeBuilder.or
to actually return aKueryNode
instead ofundefined
.Checklist