-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Update grammar to rely on indexPattern instead of identifier in join target #120494
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
Changes from 8 commits
fa962c4
6049006
610b3bc
8675905
2770dbb
58b2f27
bf9c556
a7a91b9
318fd1d
60444a8
62d53f9
a5f713f
2b642b9
52d98e6
7b38bec
2cc2643
9529874
e7d794d
62ba2fe
f562bc1
9e7f125
a9ecc24
4574fd1
856a6ec
0a39bb2
c1b399d
1116eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 120494 | ||
| summary: Update grammar to rely on `indexPattern` instead of identifier in join target | ||
| area: ES|QL | ||
| type: enhancement | ||
| issues: [] |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,8 @@ | |
| import org.elasticsearch.xpack.esql.plan.logical.Rename; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Row; | ||
| import org.elasticsearch.xpack.esql.plan.logical.UnresolvedRelation; | ||
| import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes; | ||
| import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
|
|
@@ -2939,4 +2941,69 @@ public void testNamedFunctionArgumentWithUnsupportedNamedParameterTypes() { | |
| ); | ||
| } | ||
| } | ||
|
|
||
| public void testValidJoinPattern() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the index pattern makes sense for parser (vs grammar) validation however I would have expected for patterns to be rejected from the start instead of waiting to resolve them first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 2b642b9 |
||
| var basePattern = randomIndexPatterns(); | ||
| var joinPattern = randomIndexPattern(); | ||
| var onField = randomIdentifier(); | ||
| var type = randomFrom("", "LOOKUP "); | ||
|
|
||
|
Comment on lines
+2954
to
+2955
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The empty string looks wrong - Consider removing the plain join, but it's also fine as-is due to this only testing the parsing itself. |
||
| var plan = statement("FROM " + basePattern + " | " + type + " JOIN " + joinPattern + " ON " + onField); | ||
|
|
||
| var join = as(plan, LookupJoin.class); | ||
| assertThat(as(join.left(), UnresolvedRelation.class).table().index(), equalTo(unquote(basePattern))); | ||
| assertThat(as(join.right(), UnresolvedRelation.class).table().index(), equalTo(unquote(joinPattern))); | ||
|
|
||
| var joinType = as(join.config().type(), JoinTypes.UsingJoinType.class); | ||
| assertThat(joinType.columns(), hasSize(1)); | ||
| assertThat(as(joinType.columns().getFirst(), UnresolvedAttribute.class).name(), equalTo(onField)); | ||
| assertThat(joinType.coreJoin().joinName(), equalTo("LEFT OUTER")); | ||
| } | ||
|
|
||
| private static String randomIndexPatterns() { | ||
| return maybeQuote(String.join(",", randomList(1, 5, StatementParserTests::randomIndexPattern))); | ||
| } | ||
|
|
||
| private static String randomIndexPattern() { | ||
| String pattern = maybeQuote(randomIndexIdentifier()); | ||
| if (randomBoolean()) { | ||
| var cluster = randomIdentifier(); | ||
| pattern = maybeQuote(cluster + ":" + pattern); | ||
| } | ||
| return pattern; | ||
| } | ||
|
|
||
| /** | ||
| * This generates random valid index, alias or pattern | ||
| */ | ||
| private static String randomIndexIdentifier() { | ||
| // https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#indices-create-api-path-params | ||
| var validFirstCharacters = "abcdefghijklmnopqrstuvwxyz0123456789!'$^&"; | ||
| var validCharacters = validFirstCharacters + "+-_."; | ||
|
|
||
| var index = new StringBuilder(); | ||
| if (randomInt(9) == 0) {// hidden index | ||
| index.append('.'); | ||
| } | ||
| index.append(randomCharacterFrom(validFirstCharacters)); | ||
| for (int i = 0; i < randomIntBetween(1, 100); i++) { | ||
| index.append(randomCharacterFrom(validCharacters)); | ||
| } | ||
| if (randomBoolean()) {// pattern | ||
| index.append('*'); | ||
| } | ||
| return index.toString(); | ||
| } | ||
|
|
||
| private static char randomCharacterFrom(String str) { | ||
| return str.charAt(randomInt(str.length() - 1)); | ||
| } | ||
|
|
||
| private static String maybeQuote(String term) { | ||
| return randomBoolean() && term.contains("\"") == false ? "\"" + term + "\"" : term; | ||
| } | ||
|
|
||
| private static String unquote(String term) { | ||
| return term.replace("\"", ""); | ||
| } | ||
| } | ||
ivancea marked this conversation as resolved.
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.
Add randomization to have the index specified with and without double quotes.
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 would like to keep this test simple. All possible index name variations are covered in dedicated parser test.