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

ESQL: change from quoting from backtick to quote #108395

Merged

Conversation

costin
Copy link
Member

@costin costin commented May 8, 2024

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.

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.
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 8, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @costin, I've created a changelog YAML for you.

Copy link
Contributor

@alex-spies alex-spies left a 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}}>\""
);
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

And use these csv tests in the docs for FROM; currently, I think they contain incorrect syntax (missing backticks/quotes):
image

Copy link
Contributor

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.

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4 Outdated Show resolved Hide resolved
@alex-spies alex-spies self-requested a review May 8, 2024 08:40
@alex-spies
Copy link
Contributor

Also, we'll have to update the docs for FROM.

Copy link
Contributor

@alex-spies alex-spies left a 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.

@alex-spies alex-spies self-requested a review May 8, 2024 10:59
@bpintea
Copy link
Contributor

bpintea commented May 8, 2024

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).
(Also, PUT "my_index" fails with: "reason": """Invalid index name ["my_index"], must not contain the following characters ['<','*','?','>','|',',','/','\',' ','"']""")

Copy link
Contributor

@bpintea bpintea left a 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}}>\""
);
Copy link
Contributor

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.

Copy link
Contributor

@astefan astefan left a 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.

Copy link
Contributor

@alex-spies alex-spies left a 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 :)

@costin costin removed the v8.14.1 label Jun 4, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/kibana-esql (ES|QL-ui)

@costin
Copy link
Member Author

costin commented Jun 4, 2024

I've added the target for this PR to be 8.15 (no backport to 8.14 necessary).
Since quoting (with backticks, in the old form) was removed in 8.14, this PR is just about adding regular quotes to indices for 8.15 and there's no backwards compatibility to worry about.

@costin costin force-pushed the esql/from-source-as-string-instead-of-identifier branch from c3dd636 to 9d97583 Compare June 4, 2024 21:37
@elasticsearchmachine
Copy link
Collaborator

Hi @costin, I've created a changelog YAML for you.

@bpintea
Copy link
Contributor

bpintea commented Jun 26, 2024

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

merge conflict between base and head

@bpintea
Copy link
Contributor

bpintea commented Jun 26, 2024

I think this should be followed up by updating the docs for FROM; esp. they should use examples from csv tests (currently hard-coded, manual examples) and document + illustrate the use of quotes.

I've updated the docs with just a small section on using them. This can be extended in a followup.

Since we also generalize the quoting for LOOKUP and METRICS, we should probably add some tests to that, too.

I've added some more tests, which uncovered one LOOKUP issue (unquoting).

@costin costin assigned astefan and unassigned bpintea Jun 26, 2024
@bpintea
Copy link
Contributor

bpintea commented Jun 30, 2024

@elasticmachine run elasticsearch-ci/part-3

@astefan
Copy link
Contributor

astefan commented Jun 30, 2024

@elasticmachine run elasticsearch-ci/part-3

@astefan
Copy link
Contributor

astefan commented Jun 30, 2024

@elasticmachine update branch

@astefan astefan merged commit b906ce3 into elastic:main Jun 30, 2024
15 checks passed
stratoula added a commit to elastic/kibana that referenced this pull request Jul 5, 2024
## 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]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 5, 2024
## 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)
stratoula referenced this pull request in elastic/kibana Jul 5, 2024
# 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]>
qn895 added a commit to elastic/kibana that referenced this pull request Jul 9, 2024
…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]>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jul 9, 2024
…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)
kibanamachine added a commit to elastic/kibana that referenced this pull request Jul 9, 2024
… 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-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >bug ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants