-
Notifications
You must be signed in to change notification settings - Fork 25k
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
ESQL: change from quoting from backtick to quote #108395
ESQL: change from quoting from backtick to quote #108395
Conversation
For historical reasons, the source declaration inside FROM command is treated as an identifier, using backticks (`) for escaping the value. This is inconsistent since the source is not an identifier (field name) but an index name which has different semantics. `index` means a field name index while "index" means a literal with said value. In case of FROM, the index name/location is more like a literal (also in unquoted form) than an identifier (that is a reference to a value). This PR tweaks the grammar and plugs in the quoted string logic so that both the single quote (") and triple quote (""") are allowed.
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Hi @costin, I've created a changelog YAML for you. |
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 didn't get to fully review the PR yet, but I noticed it is a breaking language change. We need to use our language version mechanism to avoid breaking existing queries.
assertIdentifierAsIndexPattern("foo,test,xyz", "from foo, test,xyz"); | ||
assertIdentifierAsIndexPattern( | ||
"<logstash-{now/M{yyyy.MM}}>,<logstash-{now/d{yyyy.MM.dd|+12:00}}>", | ||
"from <logstash-{now/M{yyyy.MM}}>, `<logstash-{now/d{yyyy.MM.dd|+12:00}}>`" | ||
"from <logstash-{now/M{yyyy.MM}}>, \"<logstash-{now/d{yyyy.MM.dd|+12:00}}>\"" | ||
); |
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 am surprised we don't need to update any csv tests - I guess we should add one or two to ensure this change also works correctly end-to-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.
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.
It'd also be great to add some tests with backticks now.
Also, we'll have to update the docs for |
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.
Another thing I noticed is that for
FROM `testidx`
we include the backticks in the parsed index pattern/name. I think backticks should not be allowed here.
I think they should be allowed (maybe surprisingly). |
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.
On one hand, this feels good since quotes aren't allowed in index names, so it feels natural to use them for quoting. OTOH, index names feel closer to identifiers than string literals and conceptually, would be easier to understand them together, as a language user.
It'd be good to have more tests with backticks now, as well as csv-specs, as noted by Alex.
It'd also be good to get it in 8.14, if we can sync this with other clients (like Kibana).
assertIdentifierAsIndexPattern("foo,test,xyz", "from foo, test,xyz"); | ||
assertIdentifierAsIndexPattern( | ||
"<logstash-{now/M{yyyy.MM}}>,<logstash-{now/d{yyyy.MM.dd|+12:00}}>", | ||
"from <logstash-{now/M{yyyy.MM}}>, `<logstash-{now/d{yyyy.MM.dd|+12:00}}>`" | ||
"from <logstash-{now/M{yyyy.MM}}>, \"<logstash-{now/d{yyyy.MM.dd|+12:00}}>\"" | ||
); |
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.
It'd also be great to add some tests with backticks now.
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 it's ok to have these as strings/constants (vs. identifiers). Until now, the backticks were more like a way of emphasizing that the index names are not regular "strings", but based on your explanation, they in essence are and I agree.
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.
Since quoting was disabled in this PR, this PR does not break bwc anymore, so my change request is moot :)
Pinging @elastic/kibana-esql (ES|QL-ui) |
I've added the target for this PR to be 8.15 (no backport to 8.14 necessary). |
c3dd636
to
9d97583
Compare
Hi @costin, I've created a changelog YAML for you. |
@elasticmachine update branch |
merge conflict between base and head |
I've updated the docs with just a small section on using them. This can be extended in a followup.
I've added some more tests, which uncovered one LOOKUP issue (unquoting). |
@elasticmachine run elasticsearch-ci/part-3 |
Co-authored-by: marciw <[email protected]>
@elasticmachine run elasticsearch-ci/part-3 |
@elasticmachine update branch |
## Summary Follow up of elastic/elasticsearch#108395 ### 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 --------- Co-authored-by: Søren Louv-Jansen <[email protected]>
## Summary Follow up of elastic/elasticsearch#108395 ### 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 --------- Co-authored-by: Søren Louv-Jansen <[email protected]> (cherry picked from commit 7b635f3)
# Backport This will backport the following commits from `main` to `8.15`: - [[Obs AI assistant] Replace with double quotes (#187327)](#187327) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Stratoula Kalafateli","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-05T10:54:45Z","message":"[Obs AI assistant] Replace with double quotes (#187327)\n\n## Summary\r\n\r\nFollow up of https://github.com/elastic/elasticsearch/pull/108395\r\n\r\n### Checklist\r\n\r\n- [ ] [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\r\n\r\n---------\r\n\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"7b635f3246d9f827380d4d89441cdfaf8aadd468","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","Team:Obs AI Assistant","ci:project-deploy-observability","v8.15.0","v8.16.0"],"title":"[Obs AI assistant] Replace with double quotes","number":187327,"url":"https://github.com/elastic/kibana/pull/187327","mergeCommit":{"message":"[Obs AI assistant] Replace with double quotes (#187327)\n\n## Summary\r\n\r\nFollow up of https://github.com/elastic/elasticsearch/pull/108395\r\n\r\n### Checklist\r\n\r\n- [ ] [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\r\n\r\n---------\r\n\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"7b635f3246d9f827380d4d89441cdfaf8aadd468"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187327","number":187327,"mergeCommit":{"message":"[Obs AI assistant] Replace with double quotes (#187327)\n\n## Summary\r\n\r\nFollow up of https://github.com/elastic/elasticsearch/pull/108395\r\n\r\n### Checklist\r\n\r\n- [ ] [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\r\n\r\n---------\r\n\r\nCo-authored-by: Søren Louv-Jansen <[email protected]>","sha":"7b635f3246d9f827380d4d89441cdfaf8aadd468"}}]}] BACKPORT--> Co-authored-by: Stratoula Kalafateli <[email protected]>
…dex names (#187212) Related to elastic/elasticsearch#108395. This PR updates the ES|QL grammars (lexer and parser) to match the latest version in Elasticsearch. The PR adds support for index names wrapped by `""`, and triple quotes `"""index-name"""` to the ES|QL text editor and removes backticks. <img width="1392" alt="Screenshot 2024-07-09 at 09 25 22" src="https://github.com/elastic/kibana/assets/43350163/4e93f503-9053-42a6-99c5-beda7bb4ba4c"> <img width="1392" alt="Screenshot 2024-07-09 at 09 24 54" src="https://github.com/elastic/kibana/assets/43350163/eec6292c-f3c0-49f0-9864-cb3e6717e7a7"> <img width="1392" alt="Screenshot 2024-07-09 at 09 25 03" src="https://github.com/elastic/kibana/assets/43350163/66dca108-a535-4df7-b1c0-42705c7913dd"> --------- Co-authored-by: Quynh Nguyen <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
…dex names (elastic#187212) Related to elastic/elasticsearch#108395. This PR updates the ES|QL grammars (lexer and parser) to match the latest version in Elasticsearch. The PR adds support for index names wrapped by `""`, and triple quotes `"""index-name"""` to the ES|QL text editor and removes backticks. <img width="1392" alt="Screenshot 2024-07-09 at 09 25 22" src="https://github.com/elastic/kibana/assets/43350163/4e93f503-9053-42a6-99c5-beda7bb4ba4c"> <img width="1392" alt="Screenshot 2024-07-09 at 09 24 54" src="https://github.com/elastic/kibana/assets/43350163/eec6292c-f3c0-49f0-9864-cb3e6717e7a7"> <img width="1392" alt="Screenshot 2024-07-09 at 09 25 03" src="https://github.com/elastic/kibana/assets/43350163/66dca108-a535-4df7-b1c0-42705c7913dd"> --------- Co-authored-by: Quynh Nguyen <[email protected]> Co-authored-by: Elastic Machine <[email protected]> (cherry picked from commit 5bc0c78)
… for index names (#187212) (#187895) # Backport This will backport the following commits from `main` to `8.15`: - [[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)](#187212) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Kibana Machine","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-09T17:18:50Z","message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to elastic/elasticsearch#108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/4e93f503-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/eec6292c-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/66dca108-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:ES|QL","Team:ESQL","v8.15.0","v8.16.0"],"title":"[ES|QL] Update grammars: change quoting from backtick to quote for index names","number":187212,"url":"https://github.com/elastic/kibana/pull/187212","mergeCommit":{"message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to elastic/elasticsearch#108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/4e93f503-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/eec6292c-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/66dca108-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187212","number":187212,"mergeCommit":{"message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to elastic/elasticsearch#108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/4e93f503-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/eec6292c-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"https://github.com/elastic/kibana/assets/43350163/66dca108-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6"}}]}] BACKPORT-->
For historical reasons, the source declaration inside FROM command is
treated as an identifier, using backticks (``) for escaping the value.
This is inconsistent since the source is not an identifier (field name)
but an index name which has different semantics.
index
means a field name index while "index" means a literal withsaid value.
In case of FROM, the index name/location is more like a literal (also in
unquoted form) than an identifier (that is a reference to a value).
This PR tweaks the grammar and plugs in the quoted string logic so that
both the single quote (") and triple quote (""") are allowed.