Skip to content

[ES|QL] Fixes the suggestion problem in where for multiline queries#213240

Merged
stratoula merged 5 commits intoelastic:mainfrom
stratoula:fix-where-autocomplete-bug
Mar 10, 2025
Merged

[ES|QL] Fixes the suggestion problem in where for multiline queries#213240
stratoula merged 5 commits intoelastic:mainfrom
stratoula:fix-where-autocomplete-bug

Conversation

@stratoula
Copy link
Contributor

@stratoula stratoula commented Mar 5, 2025

Summary

Closes #213323

This is the attempt to fix this bug:

FROM kibana_sample_data_logs
| WHERE event.dataset == # cursor on this line
| LIMIT 10

In main the suggestions do not trigger. The problem is that the range is completely wrong. The lineNumber is 3 while it should be 2 and the start and end columns are also wrong.

This PR attempts to fix it (hopefully).
meow

Checklist

) {
suggestions.push(listCompleteItem);
} else {
const finalType = leftArgType || leftArgType || 'any';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

irrelevant but I saw it and decided to fix here

}
return suggestions.map<SuggestionRawDefinition>((s) => {
const overlap = getOverlapRange(queryText, s.text);
const offset = overlap.start === overlap.end ? 1 : 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont think that this is needed unless I am missing something

Copy link
Contributor

Choose a reason for hiding this comment

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

So, you basically moved this shift to the translation step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I removed this offset gaining one position closet to the real position (it was by 2 positions wrong due to this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test because it took me some time to understand how this function works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem here is that the range.start is 2 positions after the /n and this creates the problem. So if the /n is at position 10, the start comes at 12 which causes the bug and is wrong as the range start should be either 1 position or at the same with the newline character.

  • By removing this

const offset = overlap.start === overlap.end ? 1 : 0;
the difference becomes 1 position

  • By moving the line counter in the end we ensure that the line won't increase before we end the loop if we find the position

  • I am introducing an offset here to be sure that we catch the position correctly for multilines (as I explain above the position difference is 1 here for multilines

@stratoula stratoula requested a review from drewdaemon March 6, 2025 07:03
@stratoula stratoula added v9.1.0 v8.19.0 backport:version Backport to applied version labels Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// release_note:fix labels Mar 6, 2025
@stratoula stratoula marked this pull request as ready for review March 6, 2025 07:04
@stratoula stratoula requested review from a team as code owners March 6, 2025 07:04
@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.

I've confirmed it fixes the problem. This whole issue makes my head hurt. I left some comments, including one about the tests. Hopefully they make sense...

}
return suggestions.map<SuggestionRawDefinition>((s) => {
const overlap = getOverlapRange(queryText, s.text);
const offset = overlap.start === overlap.end ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

So, you basically moved this shift to the translation step?

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.

Thank you for this fix!

@stratoula stratoula enabled auto-merge (squash) March 10, 2025 08:13
@elasticmachine
Copy link
Contributor

💚 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.6MB 3.6MB +3.0B

History

Copy link
Contributor

@eokoneyo eokoneyo left a comment

Choose a reason for hiding this comment

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

Tested locally, suggestions are presented as expected

@stratoula stratoula merged commit 6f83177 into elastic:main Mar 10, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/13764133332

@kibanamachine
Copy link
Contributor

@stratoula
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

stratoula added a commit to stratoula/kibana that referenced this pull request Mar 10, 2025
…lastic#213240)

## Summary

Closes elastic#213323

This is the attempt to fix this bug:

```
FROM kibana_sample_data_logs
| WHERE event.dataset == # cursor on this line
| LIMIT 10
```

In main the suggestions do not trigger. The problem is that the range is
completely wrong. The lineNumber is 3 while it should be 2 and the start
and end columns are also wrong.

This PR attempts to fix it (hopefully).

![meow](https://github.com/user-attachments/assets/2741891e-5186-477b-900f-ef42bb3371da)

### Checklist

- [ ] [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 6f83177)

# Conflicts:
#	src/platform/packages/shared/kbn-monaco/src/esql/lib/shared/utils.test.ts
stratoula added a commit that referenced this pull request Mar 10, 2025
…ries (#213240) (#213744)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Fixes the suggestion problem in where for multiline queries
(#213240)](#213240)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"efstratia.kalafateli@elastic.co"},"sourceCommit":{"committedDate":"2025-03-10T12:02:21Z","message":"[ES|QL]
Fixes the suggestion problem in where for multiline queries
(#213240)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/213323\n\nThis is the attempt
to fix this bug:\n\n```\nFROM kibana_sample_data_logs\n| WHERE
event.dataset == # cursor on this line\n| LIMIT 10\n```\n\nIn main the
suggestions do not trigger. The problem is that the range is\ncompletely
wrong. The lineNumber is 3 while it should be 2 and the start\nand end
columns are also wrong.\n\n\nThis PR attempts to fix it
(hopefully).\n\n![meow](https://github.com/user-attachments/assets/2741891e-5186-477b-900f-ef42bb3371da)\n\n\n###
Checklist\n\n- [ ] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"6f831770fd77456e0d5f0c4eded122709481c043","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ES|QL","Team:ESQL","backport:version","v9.1.0","v8.19.0"],"title":"[ES|QL]
Fixes the suggestion problem in where for multiline
queries","number":213240,"url":"https://github.com/elastic/kibana/pull/213240","mergeCommit":{"message":"[ES|QL]
Fixes the suggestion problem in where for multiline queries
(#213240)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/213323\n\nThis is the attempt
to fix this bug:\n\n```\nFROM kibana_sample_data_logs\n| WHERE
event.dataset == # cursor on this line\n| LIMIT 10\n```\n\nIn main the
suggestions do not trigger. The problem is that the range is\ncompletely
wrong. The lineNumber is 3 while it should be 2 and the start\nand end
columns are also wrong.\n\n\nThis PR attempts to fix it
(hopefully).\n\n![meow](https://github.com/user-attachments/assets/2741891e-5186-477b-900f-ef42bb3371da)\n\n\n###
Checklist\n\n- [ ] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"6f831770fd77456e0d5f0c4eded122709481c043"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/213240","number":213240,"mergeCommit":{"message":"[ES|QL]
Fixes the suggestion problem in where for multiline queries
(#213240)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/213323\n\nThis is the attempt
to fix this bug:\n\n```\nFROM kibana_sample_data_logs\n| WHERE
event.dataset == # cursor on this line\n| LIMIT 10\n```\n\nIn main the
suggestions do not trigger. The problem is that the range is\ncompletely
wrong. The lineNumber is 3 while it should be 2 and the start\nand end
columns are also wrong.\n\n\nThis PR attempts to fix it
(hopefully).\n\n![meow](https://github.com/user-attachments/assets/2741891e-5186-477b-900f-ef42bb3371da)\n\n\n###
Checklist\n\n- [ ] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"6f831770fd77456e0d5f0c4eded122709481c043"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
…lastic#213240)

## Summary

Closes elastic#213323

This is the attempt to fix this bug:

```
FROM kibana_sample_data_logs
| WHERE event.dataset == # cursor on this line
| LIMIT 10
```

In main the suggestions do not trigger. The problem is that the range is
completely wrong. The lineNumber is 3 while it should be 2 and the start
and end columns are also wrong.


This PR attempts to fix it (hopefully).

![meow](https://github.com/user-attachments/assets/2741891e-5186-477b-900f-ef42bb3371da)


### Checklist

- [ ] [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:ES|QL ES|QL related features in Kibana release_note:fix Team:ESQL ES|QL related features in Kibana t// v8.19.0 v9.1.0

5 participants