-
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
[ES|QL] Validate index name in parser #112081
[ES|QL] Validate index name in parser #112081
Conversation
Hi @fang-xing-esql, I've created a changelog YAML for you. |
83b3d98
to
f675063
Compare
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Hi @fang-xing-esql, 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.
Looks good. Please add more date math examples.
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java
Outdated
Show resolved
Hide resolved
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.
Unfortunately, this PR is introducing a breaking change.
A query like from test, --bla*
fails with this PR but was accepted by ES|QL before. Now, we strip the wildcard and the first minus sign and validate -bla
(which fails).
ES itself doesn't fail for localhost:9200/test,--bla*/_search
, but even if it did I am not sure we should copy the ES behavior here. ES|QL has a different behavior than ES when resolving indices anyway; see this PR for more info on that.
I would also be reluctant on validating the index names and not letting ES do it. We assume stuff when we validate the index names (we strip wildcards and the first minus sign) but is ES doing the same steps? If ES is introducing some restrictions or lifting them and those are not reflected in the two methods we borrow from ES, we risk restricting queries when ES accepts them.
I apologize for getting back to this late. Yes, there is possibility that this might introduce a breaking change... Discussed with Andrei offline, I'd like to put my analysis and experiments here. The breaking change could happen when:
I did some experiments, to compare the behavior when there is invalid index names in the query between main and branch. I haven't come across #1 yet. On today's main, if there is an index name with invalid name, or if there is a non-existing index referenced in the query. The query may fail with two exceptions:
These are what I have found so far, we do have to be very careful at validating index names in parser, not block valid indices names. |
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 the change is benefic for ES|QL ignoring the breaking changes it may introduce.
Regarding tests, I think they can be improved a bit:
- I added a comment regarding the check for the error message itself
- some tests are needed for multiple comma-separated index patterns are provided
- also,
testInvalidCharacterInIndexPattern
can be improved further andcluster:
suffix can be provided or skipped for two types of queries - the
metrics
command is a snapshot only command. Please, see other test methods in this class that skip these tests when the test is a non-snapshot run. To test your code with non-snapshot check use-Dbuild.snapshot=false -Dtests.jvm.argline="-Dbuild.snapshot=false" -Dlicense.key=x-pack/license-tools/src/test/resources/public.key
in local runs. If you'd like to do it in the PR, thetest-release
label is needed, but it will take quite a big chunk of time.
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java
Outdated
Show resolved
Hide resolved
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
…clusion unless the DateMath expression is invalid
Thanks for reviewing @bpintea and @astefan! I updated to PR according to the recent discussion about index names that start with exclusions, some more related tests are added, hope to make it more consistent with current behavior and less confusing. Just let me know if there is anything that I missed. In a summary:
|
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
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/IdentifierBuilder.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/IdentifierBuilder.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// comma separated indices | ||
// These fail because there is an invalid index name, and there is no index name with wildcard before it |
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.
Is there any test for index,-index
and/or just -index
?
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 thought about it, it is a good point. I'll add tests for index,-index
, I'll leave it to the IndicesOptions
to decide whether to error out or not.
💔 Backport failedThe backport operation could not be completed due to the following error:
You can use sqren/backport to manually backport by running |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
* validate index name in parser (cherry picked from commit 91dca8d)
* validate index name in parser
* validate index name in parser
Resolves: #112040
Calls ES APIs to validate index names in parser.